diff options
author | 2016-12-19 08:03:06 -0500 | |
---|---|---|
committer | 2016-12-19 08:03:06 -0500 | |
commit | c83cda35d3466a9eb4c7d35c4641d490d9e0475b (patch) | |
tree | f7553fa1be04f7a8c1a7975b6fa46e505fdec5e4 /src | |
parent | Merge pull request #990 from pmillerchip/private-blacklist (diff) | |
parent | appimage: pass commandline arguments (diff) | |
download | firejail-c83cda35d3466a9eb4c7d35c4641d490d9e0475b.tar.gz firejail-c83cda35d3466a9eb4c7d35c4641d490d9e0475b.tar.zst firejail-c83cda35d3466a9eb4c7d35c4641d490d9e0475b.zip |
Merge pull request #991 from thewisenerd/master
appimage: pass commandline arguments
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/cmdline.c | 44 | ||||
-rw-r--r-- | src/firejail/firejail.h | 1 | ||||
-rw-r--r-- | src/firejail/main.c | 2 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/firejail/cmdline.c b/src/firejail/cmdline.c index cadf4795d..dcb0a5424 100644 --- a/src/firejail/cmdline.c +++ b/src/firejail/cmdline.c | |||
@@ -157,3 +157,47 @@ void build_cmdline(char **command_line, char **window_title, int argc, char **ar | |||
157 | assert(*command_line); | 157 | assert(*command_line); |
158 | assert(*window_title); | 158 | assert(*window_title); |
159 | } | 159 | } |
160 | |||
161 | void build_appimage_cmdline(char **command_line, char **window_title, int argc, char **argv, int index, char *apprun_path) { | ||
162 | // index == -1 could happen if we have --shell=none and no program was specified | ||
163 | // the program should exit with an error before entering this function | ||
164 | assert(index != -1); | ||
165 | |||
166 | unsigned argcount = argc - index; | ||
167 | |||
168 | int len1 = cmdline_length(argc, argv, index); // length of argv w/o changes | ||
169 | int len2 = cmdline_length(1, &argv[index], 0); // apptest.AppImage | ||
170 | int len3 = cmdline_length(1, &apprun_path, 0); // /run/firejail/appimage/.appimage-23304/AppRun | ||
171 | int len4 = (len1 - len2 + len3) + 1; // apptest.AppImage is replaced by /path/to/AppRun | ||
172 | |||
173 | if (len4 > ARG_MAX) { | ||
174 | errno = E2BIG; | ||
175 | errExit("cmdline_length"); | ||
176 | } | ||
177 | |||
178 | // save created apprun in cfg.command_line | ||
179 | char *tmp1 = strdup(*command_line); | ||
180 | if (!tmp1) | ||
181 | errExit("strdup"); | ||
182 | |||
183 | // TODO: deal with extra allocated memory. | ||
184 | char *command_line_tmp = malloc(len1 + len3 + 1); | ||
185 | if (!command_line_tmp) | ||
186 | errExit("malloc"); | ||
187 | *window_title = malloc(len1 + len3 + 1); | ||
188 | if (!*window_title) | ||
189 | errExit("malloc"); | ||
190 | |||
191 | // run default quote_cmdline | ||
192 | quote_cmdline(command_line_tmp, *window_title, len1, argc, argv, index); | ||
193 | |||
194 | assert(command_line_tmp); | ||
195 | assert(*window_title); | ||
196 | |||
197 | // 'fix' command_line now | ||
198 | if (asprintf(command_line, "'%s' %s", tmp1, command_line_tmp + len2) == -1) | ||
199 | errExit("asprintf"); | ||
200 | |||
201 | // free strdup | ||
202 | free(tmp1); | ||
203 | } | ||
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index de939439d..36cf47435 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -683,6 +683,7 @@ long unsigned int appimage2_size(const char *fname); | |||
683 | 683 | ||
684 | // cmdline.c | 684 | // cmdline.c |
685 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index); | 685 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index); |
686 | void build_appimage_cmdline(char **command_line, char **window_title, int argc, char **argv, int index, char *apprun_path); | ||
686 | 687 | ||
687 | // sbox.c | 688 | // sbox.c |
688 | // programs | 689 | // programs |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 65d2b9d44..15820f7dd 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -2160,7 +2160,7 @@ int main(int argc, char **argv) { | |||
2160 | if (arg_debug) | 2160 | if (arg_debug) |
2161 | printf("Configuring appimage environment\n"); | 2161 | printf("Configuring appimage environment\n"); |
2162 | appimage_set(cfg.command_name); | 2162 | appimage_set(cfg.command_name); |
2163 | cfg.window_title = "appimage"; | 2163 | build_appimage_cmdline(&cfg.command_line, &cfg.window_title, argc, argv, prog_index, cfg.command_line); |
2164 | } | 2164 | } |
2165 | else { | 2165 | else { |
2166 | build_cmdline(&cfg.command_line, &cfg.window_title, argc, argv, prog_index); | 2166 | build_cmdline(&cfg.command_line, &cfg.window_title, argc, argv, prog_index); |