aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2010-09-08 20:23:25 +0800
committermaximilian attems <max@stro.at>2011-06-03 18:44:13 +0200
commit4dea851664630da8d688de9cc3bdd7d6a853af08 (patch)
treec2c9f1d9441eda81c33fa558bcfc2818cfce32a7
parent1db0c896084ef8dc7020ce8f14b96f155500f364 (diff)
downloadklibc-4dea851664630da8d688de9cc3bdd7d6a853af08.tar.gz
[klibc] [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> Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r--usr/dash/miscbltin.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/usr/dash/miscbltin.c b/usr/dash/miscbltin.c
index d67fd90927d49..152337b9897f9 100644
--- a/usr/dash/miscbltin.c
+++ b/usr/dash/miscbltin.c
@@ -92,9 +92,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;
@@ -111,12 +122,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);
}