diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-13 06:47:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-13 06:47:47 +0000 |
commit | d67cef2425fb5e75b75d52d9a308da6d29cd7a0d (patch) | |
tree | 5d034f518dfae9a933a701e8c42da4acbf0cb42d /shell | |
parent | f5f75c5e82d47613847c356664e47c4be69e73aa (diff) | |
download | busybox-w32-d67cef2425fb5e75b75d52d9a308da6d29cd7a0d.tar.gz busybox-w32-d67cef2425fb5e75b75d52d9a308da6d29cd7a0d.tar.bz2 busybox-w32-d67cef2425fb5e75b75d52d9a308da6d29cd7a0d.zip |
hush: fix read builtin to not read ahead past eol and to not use
insane amounts of stack. Testsuite updated.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/README | 3 | ||||
-rw-r--r-- | shell/ash.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 16 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/read.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/read.tests | 4 |
5 files changed, 16 insertions, 15 deletions
diff --git a/shell/README b/shell/README index a09353d6c..b86f96cf4 100644 --- a/shell/README +++ b/shell/README | |||
@@ -1,5 +1,8 @@ | |||
1 | Various bits of what is known about busybox shells, in no particular order. | 1 | Various bits of what is known about busybox shells, in no particular order. |
2 | 2 | ||
3 | 2007-06-13 | ||
4 | hush: exec <"$1" doesn't do parameter subst | ||
5 | |||
3 | 2007-05-24 | 6 | 2007-05-24 |
4 | hush: environment-related memory leak plugged, with net code size | 7 | hush: environment-related memory leak plugged, with net code size |
5 | decrease. | 8 | decrease. |
diff --git a/shell/ash.c b/shell/ash.c index ae078e609..173beb195 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11567,8 +11567,8 @@ readcmd(int argc, char **argv) | |||
11567 | #endif | 11567 | #endif |
11568 | #if ENABLE_ASH_READ_TIMEOUT | 11568 | #if ENABLE_ASH_READ_TIMEOUT |
11569 | if (ts.tv_sec || ts.tv_usec) { | 11569 | if (ts.tv_sec || ts.tv_usec) { |
11570 | FD_ZERO (&set); | 11570 | FD_ZERO(&set); |
11571 | FD_SET (0, &set); | 11571 | FD_SET(0, &set); |
11572 | 11572 | ||
11573 | i = select(FD_SETSIZE, &set, NULL, NULL, &ts); | 11573 | i = select(FD_SETSIZE, &set, NULL, NULL, &ts); |
11574 | if (!i) { | 11574 | if (!i) { |
diff --git a/shell/hush.c b/shell/hush.c index 40bcafdd9..e6fa3d9a5 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -942,21 +942,11 @@ static int builtin_pwd(char **argv ATTRIBUTE_UNUSED) | |||
942 | /* built-in 'read VAR' handler */ | 942 | /* built-in 'read VAR' handler */ |
943 | static int builtin_read(char **argv) | 943 | static int builtin_read(char **argv) |
944 | { | 944 | { |
945 | char string[BUFSIZ]; | 945 | char *string; |
946 | char *p; | ||
947 | const char *name = argv[1] ? argv[1] : "REPLY"; | 946 | const char *name = argv[1] ? argv[1] : "REPLY"; |
948 | int name_len = strlen(name); | ||
949 | 947 | ||
950 | if (name_len >= sizeof(string) - 2) | 948 | string = xmalloc_reads(STDIN_FILENO, xasprintf("%s=", name)); |
951 | return EXIT_FAILURE; | 949 | return set_local_var(string, 0); |
952 | strcpy(string, name); | ||
953 | p = string + name_len; | ||
954 | *p++ = '='; | ||
955 | *p = '\0'; /* In case stdin has only EOF */ | ||
956 | /* read string. name_len+1 chars are already used by 'name=' */ | ||
957 | fgets(p, sizeof(string) - 1 - name_len, stdin); | ||
958 | chomp(p); | ||
959 | return set_local_var(xstrdup(string), 0); | ||
960 | } | 950 | } |
961 | 951 | ||
962 | /* built-in 'set [VAR=value]' handler */ | 952 | /* built-in 'set [VAR=value]' handler */ |
diff --git a/shell/hush_test/hush-misc/read.right b/shell/hush_test/hush-misc/read.right new file mode 100644 index 000000000..0e50e2a23 --- /dev/null +++ b/shell/hush_test/hush-misc/read.right | |||
@@ -0,0 +1,4 @@ | |||
1 | read | ||
2 | cat | ||
3 | echo "REPLY=$REPLY" | ||
4 | REPLY=exec <read.tests | ||
diff --git a/shell/hush_test/hush-misc/read.tests b/shell/hush_test/hush-misc/read.tests new file mode 100755 index 000000000..ff1acbde1 --- /dev/null +++ b/shell/hush_test/hush-misc/read.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | exec <read.tests | ||
2 | read | ||
3 | cat | ||
4 | echo "REPLY=$REPLY" | ||