hush: fix read builtin to not read ahead past eol and to not use

insane amounts of stack. Testsuite updated.
This commit is contained in:
Denis Vlasenko
2007-06-13 06:47:47 +00:00
parent f5f75c5e82
commit d67cef2425
10 changed files with 68 additions and 31 deletions

View File

@@ -1,5 +1,8 @@
Various bits of what is known about busybox shells, in no particular order.
2007-06-13
hush: exec <"$1" doesn't do parameter subst
2007-05-24
hush: environment-related memory leak plugged, with net code size
decrease.

View File

@@ -11567,8 +11567,8 @@ readcmd(int argc, char **argv)
#endif
#if ENABLE_ASH_READ_TIMEOUT
if (ts.tv_sec || ts.tv_usec) {
FD_ZERO (&set);
FD_SET (0, &set);
FD_ZERO(&set);
FD_SET(0, &set);
i = select(FD_SETSIZE, &set, NULL, NULL, &ts);
if (!i) {

View File

@@ -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 */

View File

@@ -0,0 +1,4 @@
read
cat
echo "REPLY=$REPLY"
REPLY=exec <read.tests

View File

@@ -0,0 +1,4 @@
exec <read.tests
read
cat
echo "REPLY=$REPLY"