diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2010-09-08 20:23:25 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-09-08 20:23:25 +0800 |
commit | b61ab0b33b4f9ea5fb3663fe8fa0d5fd70e6c166 (patch) | |
tree | 4794b21ddac4ea469d2902342c169628d905cd95 | |
parent | [EXPAND] Fix ifsfirst/ifslastp leak (diff) | |
download | dash-b61ab0b33b4f9ea5fb3663fe8fa0d5fd70e6c166.tar.gz dash-b61ab0b33b4f9ea5fb3663fe8fa0d5fd70e6c166.zip |
[BUILTIN] Fix trailing field bug in read(1)
The new read(1) code fails to handle the last variable correctly if it happens to be terminated by IFS characters. Those characters are included in the last variable but they should not be. This patch fixes this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/miscbltin.c | 22 |
2 files changed, 15 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog index a51975c..1dfe241 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2010-09-08 Herbert Xu <herbert@gondor.apana.org.au> * Fix ifsfirst/ifslastp leak. + * Fix trailing field bug in read(1). 2010-09-08 maximilian attems <max@stro.at> diff --git a/src/miscbltin.c b/src/miscbltin.c index c42a01c..653c92f 100644 --- a/src/miscbltin.c +++ b/src/miscbltin.c @@ -91,9 +91,20 @@ readcmd_handle_line(char *line, char **ap, size_t len) *arglist.lastp = NULL; ifsfree(); - for (sl = arglist.list; sl; sl = sl->next) { + sl = arglist.list; + + do { + if (!sl) { + /* nullify remaining arguments */ + do { + setvar(*ap, nullstr, 0); + } while (*++ap); + + return; + } + /* remaining fields present, but no variables left. */ - if (!ap[1]) { + if (!ap[1] && sl->next) { size_t offset; char *remainder; @@ -110,12 +121,7 @@ readcmd_handle_line(char *line, char **ap, size_t len) /* set variable to field */ rmescapes(sl->text); setvar(*ap, sl->text, 0); - ap++; - } - - /* nullify remaining arguments */ - do { - setvar(*ap, nullstr, 0); + sl = sl->next; } while (*++ap); } |