diff options
author | 2016-08-14 10:06:13 -0400 | |
---|---|---|
committer | 2016-08-14 10:06:13 -0400 | |
commit | c85c8d2c7f23ab03276fcd7ae052a18a68e05d16 (patch) | |
tree | e0810c6bcc9f03dfa722f279f73eda3cd9a08e5f /src | |
parent | Merge pull request #709 from manevich/shell (diff) | |
download | firejail-c85c8d2c7f23ab03276fcd7ae052a18a68e05d16.tar.gz firejail-c85c8d2c7f23ab03276fcd7ae052a18a68e05d16.tar.zst firejail-c85c8d2c7f23ab03276fcd7ae052a18a68e05d16.zip |
gether shell selection code in one place
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/cmdline.c | 12 | ||||
-rw-r--r-- | src/firejail/main.c | 8 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/firejail/cmdline.c b/src/firejail/cmdline.c index 48cbaffb7..cadf4795d 100644 --- a/src/firejail/cmdline.c +++ b/src/firejail/cmdline.c | |||
@@ -26,7 +26,9 @@ | |||
26 | #include <assert.h> | 26 | #include <assert.h> |
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | 28 | ||
29 | int cmdline_length(int argc, char **argv, int index) { | 29 | static int cmdline_length(int argc, char **argv, int index) { |
30 | assert(index != -1); | ||
31 | |||
30 | unsigned i,j; | 32 | unsigned i,j; |
31 | int len = 0; | 33 | int len = 0; |
32 | unsigned argcnt = argc - index; | 34 | unsigned argcnt = argc - index; |
@@ -62,7 +64,9 @@ int cmdline_length(int argc, char **argv, int index) { | |||
62 | return len; | 64 | return len; |
63 | } | 65 | } |
64 | 66 | ||
65 | void quote_cmdline(char *command_line, char *window_title, int len, int argc, char **argv, int index) { | 67 | static void quote_cmdline(char *command_line, char *window_title, int len, int argc, char **argv, int index) { |
68 | assert(index != -1); | ||
69 | |||
66 | unsigned i,j; | 70 | unsigned i,j; |
67 | unsigned argcnt = argc - index; | 71 | unsigned argcnt = argc - index; |
68 | bool in_quotes = false; | 72 | bool in_quotes = false; |
@@ -131,6 +135,10 @@ void quote_cmdline(char *command_line, char *window_title, int len, int argc, ch | |||
131 | } | 135 | } |
132 | 136 | ||
133 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index) { | 137 | void build_cmdline(char **command_line, char **window_title, int argc, char **argv, int index) { |
138 | // index == -1 could happen if we have --shell=none and no program was specified | ||
139 | // the program should exit with an error before entering this function | ||
140 | assert(index != -1); | ||
141 | |||
134 | int len = cmdline_length(argc, argv, index); | 142 | int len = cmdline_length(argc, argv, index); |
135 | if (len > ARG_MAX) { | 143 | if (len > ARG_MAX) { |
136 | errno = E2BIG; | 144 | errno = E2BIG; |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 7cc9f9bf6..49018860a 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -1974,6 +1974,12 @@ int main(int argc, char **argv) { | |||
1974 | break; | 1974 | break; |
1975 | } | 1975 | } |
1976 | } | 1976 | } |
1977 | |||
1978 | // prog_index could still be -1 if no program was specified | ||
1979 | if (prog_index == -1 && arg_shell_none) { | ||
1980 | fprintf(stderr, "shell=none configured, but no program specified\n"); | ||
1981 | exit(1); | ||
1982 | } | ||
1977 | 1983 | ||
1978 | // check trace configuration | 1984 | // check trace configuration |
1979 | if (arg_trace && arg_tracelog) { | 1985 | if (arg_trace && arg_tracelog) { |
@@ -2027,7 +2033,9 @@ int main(int argc, char **argv) { | |||
2027 | cfg.window_title = "appimage"; | 2033 | cfg.window_title = "appimage"; |
2028 | } | 2034 | } |
2029 | else { | 2035 | else { |
2036 | printf("here %d\n", __LINE__); | ||
2030 | build_cmdline(&cfg.command_line, &cfg.window_title, argc, argv, prog_index); | 2037 | build_cmdline(&cfg.command_line, &cfg.window_title, argc, argv, prog_index); |
2038 | printf("here %d\n", __LINE__); | ||
2031 | } | 2039 | } |
2032 | /* else { | 2040 | /* else { |
2033 | fprintf(stderr, "Error: command must be specified when --shell=none used.\n"); | 2041 | fprintf(stderr, "Error: command must be specified when --shell=none used.\n"); |