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/hush.c | |
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/hush.c')
-rw-r--r-- | shell/hush.c | 16 |
1 files changed, 3 insertions, 13 deletions
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 */ |