diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-09 01:39:02 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-09 01:39:02 +0000 |
| commit | a2218dd862d392853a7d30a764acda30a478ca3f (patch) | |
| tree | bfe4d0cd4626f16b738b74a7f38a68bf26dfba1a /shell | |
| parent | 5c090a96f98f5a70af792945aa41ea53f82f39e2 (diff) | |
| download | busybox-w32-a2218dd862d392853a7d30a764acda30a478ca3f.tar.gz busybox-w32-a2218dd862d392853a7d30a764acda30a478ca3f.tar.bz2 busybox-w32-a2218dd862d392853a7d30a764acda30a478ca3f.zip | |
hush: fix thinko in re_execute_shell; pass even less junk to heredoc helper
function old new delta
re_execute_shell 284 314 +30
setup_heredoc 290 303 +13
execv 23 - -23
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c index 9920e98c6..3959da1ea 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -2180,10 +2180,21 @@ static void re_execute_shell(const char *s, int is_heredoc) NORETURN; | |||
| 2180 | static void re_execute_shell(const char *s, int is_heredoc) | 2180 | static void re_execute_shell(const char *s, int is_heredoc) |
| 2181 | { | 2181 | { |
| 2182 | char param_buf[sizeof("-$%x:%x:%x:%x") + sizeof(unsigned) * 4]; | 2182 | char param_buf[sizeof("-$%x:%x:%x:%x") + sizeof(unsigned) * 4]; |
| 2183 | char *heredoc_argv[4]; | ||
| 2183 | struct variable *cur; | 2184 | struct variable *cur; |
| 2184 | char **argv, **pp, **pp2; | 2185 | char **argv, **pp, **pp2; |
| 2185 | unsigned cnt; | 2186 | unsigned cnt; |
| 2186 | 2187 | ||
| 2188 | if (is_heredoc) { | ||
| 2189 | argv = heredoc_argv; | ||
| 2190 | argv[0] = (char *) G.argv0_for_re_execing; | ||
| 2191 | argv[1] = (char *) "-<"; | ||
| 2192 | argv[2] = (char *) s; | ||
| 2193 | argv[3] = NULL; | ||
| 2194 | pp = &argv[3]; /* used as pointer to empty environmaent */ | ||
| 2195 | goto do_exec; | ||
| 2196 | } | ||
| 2197 | |||
| 2187 | sprintf(param_buf, "-$%x:%x:%x" USE_HUSH_LOOPS(":%x") | 2198 | sprintf(param_buf, "-$%x:%x:%x" USE_HUSH_LOOPS(":%x") |
| 2188 | , (unsigned) G.root_pid | 2199 | , (unsigned) G.root_pid |
| 2189 | , (unsigned) G.last_bg_pid | 2200 | , (unsigned) G.last_bg_pid |
| @@ -2198,7 +2209,7 @@ static void re_execute_shell(const char *s, int is_heredoc) | |||
| 2198 | if (!cur->flg_export || cur->flg_read_only) | 2209 | if (!cur->flg_export || cur->flg_read_only) |
| 2199 | cnt += 2; | 2210 | cnt += 2; |
| 2200 | } | 2211 | } |
| 2201 | G.argv_from_re_execing = pp = xzalloc(sizeof(argv[0]) * cnt); | 2212 | G.argv_from_re_execing = argv = pp = xzalloc(sizeof(argv[0]) * cnt); |
| 2202 | *pp++ = (char *) G.argv0_for_re_execing; | 2213 | *pp++ = (char *) G.argv0_for_re_execing; |
| 2203 | *pp++ = param_buf; | 2214 | *pp++ = param_buf; |
| 2204 | for (cur = G.top_var; cur; cur = cur->next) { | 2215 | for (cur = G.top_var; cur; cur = cur->next) { |
| @@ -2232,22 +2243,21 @@ static void re_execute_shell(const char *s, int is_heredoc) | |||
| 2232 | * I conclude it means we don't need to pass active traps here. | 2243 | * I conclude it means we don't need to pass active traps here. |
| 2233 | * exec syscall below resets them to SIG_DFL for us. | 2244 | * exec syscall below resets them to SIG_DFL for us. |
| 2234 | */ | 2245 | */ |
| 2235 | *pp++ = (char *) (is_heredoc ? "-<" : "-c"); | 2246 | *pp++ = (char *) "-c"; |
| 2236 | *pp++ = (char *) s; | 2247 | *pp++ = (char *) s; |
| 2237 | pp2 = G.global_argv; | 2248 | pp2 = G.global_argv; |
| 2238 | while (*pp2) | 2249 | while (*pp2) |
| 2239 | *pp++ = *pp2++; | 2250 | *pp++ = *pp2++; |
| 2240 | /* *pp = NULL; - is already there */ | 2251 | /* *pp = NULL; - is already there */ |
| 2252 | pp = environ; | ||
| 2241 | 2253 | ||
| 2254 | do_exec: | ||
| 2242 | debug_printf_exec("re_execute_shell pid:%d cmd:'%s'\n", getpid(), s); | 2255 | debug_printf_exec("re_execute_shell pid:%d cmd:'%s'\n", getpid(), s); |
| 2243 | sigprocmask(SIG_SETMASK, &G.inherited_set, NULL); | 2256 | sigprocmask(SIG_SETMASK, &G.inherited_set, NULL); |
| 2244 | execve(bb_busybox_exec_path, | 2257 | execve(bb_busybox_exec_path, argv, pp); |
| 2245 | G.argv_from_re_execing, | ||
| 2246 | (is_heredoc ? pp /* points to NULL ptr */ : environ) | ||
| 2247 | ); | ||
| 2248 | /* Fallback. Useful for init=/bin/hush usage etc */ | 2258 | /* Fallback. Useful for init=/bin/hush usage etc */ |
| 2249 | if (G.argv0_for_re_execing[0] == '/') | 2259 | if (argv[0][0] == '/') |
| 2250 | execv(G.argv0_for_re_execing, G.argv_from_re_execing); | 2260 | execve(argv[0], argv, pp); |
| 2251 | xfunc_error_retval = 127; | 2261 | xfunc_error_retval = 127; |
| 2252 | bb_error_msg_and_die("can't re-execute the shell"); | 2262 | bb_error_msg_and_die("can't re-execute the shell"); |
| 2253 | } | 2263 | } |
| @@ -2281,6 +2291,7 @@ static void setup_heredoc(struct redir_struct *redir) | |||
| 2281 | } | 2291 | } |
| 2282 | len = strlen(heredoc); | 2292 | len = strlen(heredoc); |
| 2283 | 2293 | ||
| 2294 | close(redir->rd_fd); /* often saves dup2+close in xmove_fd */ | ||
| 2284 | xpiped_pair(pair); | 2295 | xpiped_pair(pair); |
| 2285 | xmove_fd(pair.rd, redir->rd_fd); | 2296 | xmove_fd(pair.rd, redir->rd_fd); |
| 2286 | 2297 | ||
