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) |
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) /* built-in 'read VAR' handler */ static int builtin_read(char **argv) { - char string[BUFSIZ]; - char *p; + char *string; const char *name = argv[1] ? argv[1] : "REPLY"; - int name_len = strlen(name); - if (name_len >= sizeof(string) - 2) - return EXIT_FAILURE; - strcpy(string, name); - p = string + name_len; - *p++ = '='; - *p = '\0'; /* In case stdin has only EOF */ - /* read string. name_len+1 chars are already used by 'name=' */ - fgets(p, sizeof(string) - 1 - name_len, stdin); - chomp(p); - return set_local_var(xstrdup(string), 0); + string = xmalloc_reads(STDIN_FILENO, xasprintf("%s=", name)); + return set_local_var(string, 0); } /* built-in 'set [VAR=value]' handler */ |