diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-11 13:17:30 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-11 13:17:30 +0100 |
commit | 1f1911239c0874d49a31d0ef2e618d0a1086a8df (patch) | |
tree | ebf78e950ff4cc7445ed7dfa9888a21c84c347af /shell | |
parent | 932b9971d05d26e353f56bdd93daec3c9f764312 (diff) | |
download | busybox-w32-1f1911239c0874d49a31d0ef2e618d0a1086a8df.tar.gz busybox-w32-1f1911239c0874d49a31d0ef2e618d0a1086a8df.tar.bz2 busybox-w32-1f1911239c0874d49a31d0ef2e618d0a1086a8df.zip |
hush: fix handling of ^C in eval
function old new delta
run_list 1044 1259 +215
builtin_eval 45 126 +81
expand_strvec_to_string 91 - -91
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/0 up/down: 296/-91) Total: 205 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash_test/ash-misc/control_char2.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-misc/control_char2.tests | 3 | ||||
-rw-r--r-- | shell/hush.c | 30 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/control_char2.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/control_char2.tests | 3 |
5 files changed, 36 insertions, 4 deletions
diff --git a/shell/ash_test/ash-misc/control_char2.right b/shell/ash_test/ash-misc/control_char2.right new file mode 100644 index 000000000..9498b420d --- /dev/null +++ b/shell/ash_test/ash-misc/control_char2.right | |||
@@ -0,0 +1,2 @@ | |||
1 | |||
2 | Done:0 | ||
diff --git a/shell/ash_test/ash-misc/control_char2.tests b/shell/ash_test/ash-misc/control_char2.tests new file mode 100755 index 000000000..e77d7a1a6 --- /dev/null +++ b/shell/ash_test/ash-misc/control_char2.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | c=`printf '\3'` | ||
2 | eval "echo $c" | ||
3 | echo Done:$? | ||
diff --git a/shell/hush.c b/shell/hush.c index 48f503cb6..c2b987f49 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -6199,7 +6199,7 @@ static char *expand_string_to_string(const char *str, int do_unbackslash) | |||
6199 | return (char*)list; | 6199 | return (char*)list; |
6200 | } | 6200 | } |
6201 | 6201 | ||
6202 | /* Used for "eval" builtin and case string */ | 6202 | #if ENABLE_HUSH_CASE |
6203 | static char* expand_strvec_to_string(char **argv) | 6203 | static char* expand_strvec_to_string(char **argv) |
6204 | { | 6204 | { |
6205 | char **list; | 6205 | char **list; |
@@ -6221,6 +6221,7 @@ static char* expand_strvec_to_string(char **argv) | |||
6221 | debug_printf_expand("strvec_to_string='%s'\n", (char*)list); | 6221 | debug_printf_expand("strvec_to_string='%s'\n", (char*)list); |
6222 | return (char*)list; | 6222 | return (char*)list; |
6223 | } | 6223 | } |
6224 | #endif | ||
6224 | 6225 | ||
6225 | static char **expand_assignments(char **argv, int count) | 6226 | static char **expand_assignments(char **argv, int count) |
6226 | { | 6227 | { |
@@ -9349,13 +9350,34 @@ static int FAST_FUNC builtin_eval(char **argv) | |||
9349 | int rcode = EXIT_SUCCESS; | 9350 | int rcode = EXIT_SUCCESS; |
9350 | 9351 | ||
9351 | argv = skip_dash_dash(argv); | 9352 | argv = skip_dash_dash(argv); |
9352 | if (*argv) { | 9353 | if (argv[0]) { |
9353 | char *str = expand_strvec_to_string(argv); | 9354 | char *str = NULL; |
9355 | |||
9356 | if (argv[1]) { | ||
9357 | /* "The eval utility shall construct a command by | ||
9358 | * concatenating arguments together, separating | ||
9359 | * each with a <space> character." | ||
9360 | */ | ||
9361 | char *p; | ||
9362 | unsigned len = 0; | ||
9363 | char **pp = argv; | ||
9364 | do | ||
9365 | len += strlen(*pp) + 1; | ||
9366 | while (*++pp); | ||
9367 | str = p = xmalloc(len); | ||
9368 | pp = argv; | ||
9369 | do { | ||
9370 | p = stpcpy(p, *pp); | ||
9371 | *p++ = ' '; | ||
9372 | } while (*++pp); | ||
9373 | p[-1] = '\0'; | ||
9374 | } | ||
9375 | |||
9354 | /* bash: | 9376 | /* bash: |
9355 | * eval "echo Hi; done" ("done" is syntax error): | 9377 | * eval "echo Hi; done" ("done" is syntax error): |
9356 | * "echo Hi" will not execute too. | 9378 | * "echo Hi" will not execute too. |
9357 | */ | 9379 | */ |
9358 | parse_and_run_string(str); | 9380 | parse_and_run_string(str ? str : argv[0]); |
9359 | free(str); | 9381 | free(str); |
9360 | rcode = G.last_exitcode; | 9382 | rcode = G.last_exitcode; |
9361 | } | 9383 | } |
diff --git a/shell/hush_test/hush-misc/control_char2.right b/shell/hush_test/hush-misc/control_char2.right new file mode 100644 index 000000000..9498b420d --- /dev/null +++ b/shell/hush_test/hush-misc/control_char2.right | |||
@@ -0,0 +1,2 @@ | |||
1 | |||
2 | Done:0 | ||
diff --git a/shell/hush_test/hush-misc/control_char2.tests b/shell/hush_test/hush-misc/control_char2.tests new file mode 100755 index 000000000..e77d7a1a6 --- /dev/null +++ b/shell/hush_test/hush-misc/control_char2.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | c=`printf '\3'` | ||
2 | eval "echo $c" | ||
3 | echo Done:$? | ||