aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-11 13:17:30 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-11 13:17:30 +0100
commit1f1911239c0874d49a31d0ef2e618d0a1086a8df (patch)
treeebf78e950ff4cc7445ed7dfa9888a21c84c347af
parent932b9971d05d26e353f56bdd93daec3c9f764312 (diff)
downloadbusybox-1f1911239c0874d49a31d0ef2e618d0a1086a8df.tar.gz
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>
-rw-r--r--shell/ash_test/ash-misc/control_char2.right2
-rwxr-xr-xshell/ash_test/ash-misc/control_char2.tests3
-rw-r--r--shell/hush.c30
-rw-r--r--shell/hush_test/hush-misc/control_char2.right2
-rwxr-xr-xshell/hush_test/hush-misc/control_char2.tests3
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 @@
+
+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 @@
+c=`printf '\3'`
+eval "echo $c"
+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)
return (char*)list;
}
-/* Used for "eval" builtin and case string */
+#if ENABLE_HUSH_CASE
static char* expand_strvec_to_string(char **argv)
{
char **list;
@@ -6221,6 +6221,7 @@ static char* expand_strvec_to_string(char **argv)
debug_printf_expand("strvec_to_string='%s'\n", (char*)list);
return (char*)list;
}
+#endif
static char **expand_assignments(char **argv, int count)
{
@@ -9349,13 +9350,34 @@ static int FAST_FUNC builtin_eval(char **argv)
int rcode = EXIT_SUCCESS;
argv = skip_dash_dash(argv);
- if (*argv) {
- char *str = expand_strvec_to_string(argv);
+ if (argv[0]) {
+ char *str = NULL;
+
+ if (argv[1]) {
+ /* "The eval utility shall construct a command by
+ * concatenating arguments together, separating
+ * each with a <space> character."
+ */
+ char *p;
+ unsigned len = 0;
+ char **pp = argv;
+ do
+ len += strlen(*pp) + 1;
+ while (*++pp);
+ str = p = xmalloc(len);
+ pp = argv;
+ do {
+ p = stpcpy(p, *pp);
+ *p++ = ' ';
+ } while (*++pp);
+ p[-1] = '\0';
+ }
+
/* bash:
* eval "echo Hi; done" ("done" is syntax error):
* "echo Hi" will not execute too.
*/
- parse_and_run_string(str);
+ parse_and_run_string(str ? str : argv[0]);
free(str);
rcode = G.last_exitcode;
}
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 @@
+
+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 @@
+c=`printf '\3'`
+eval "echo $c"
+echo Done:$?