summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenis Vlasenko2009-03-31 19:18:17 +0000
committerDenis Vlasenko2009-03-31 19:18:17 +0000
commit46aeab9a349d097307a87d7dfde3057f9e4e6722 (patch)
treed348fadeb6bc0766c21bfc850a174a059fe4c732 /shell/ash.c
parent7566bae19715a493f40fd3fae4d69d10089af411 (diff)
downloadbusybox-46aeab9a349d097307a87d7dfde3057f9e4e6722.zip
busybox-46aeab9a349d097307a87d7dfde3057f9e4e6722.tar.gz
ash: fix $IFS handling in read. closes bug 235
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 13b4329..1de989e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12574,7 +12574,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#endif
status = 0;
- startword = 1;
+ startword = 2;
backslash = 0;
#if ENABLE_ASH_READ_TIMEOUT
if (timeout) /* NB: ensuring end_ms is nonzero */
@@ -12582,6 +12582,8 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#endif
STARTSTACKSTR(p);
do {
+ const char *is_ifs;
+
#if ENABLE_ASH_READ_TIMEOUT
if (end_ms) {
struct pollfd pfd[1];
@@ -12611,25 +12613,34 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
continue;
}
if (!rflag && c == '\\') {
- backslash++;
+ backslash = 1;
continue;
}
if (c == '\n')
break;
- if (startword && *ifs == ' ' && strchr(ifs, c)) {
- continue;
+ is_ifs = strchr(ifs, c);
+ if (startword && is_ifs) {
+ if (isspace(c))
+ continue;
+ /* non-space ifs char */
+ startword--;
+ if (startword == 1) /* first one? */
+ continue;
}
startword = 0;
- if (ap[1] != NULL && strchr(ifs, c) != NULL) {
+ if (ap[1] != NULL && is_ifs) {
+ const char *beg;
STACKSTRNUL(p);
- setvar(*ap, stackblock(), 0);
+ beg = stackblock();
+ setvar(*ap, beg, 0);
ap++;
- startword = 1;
+ /* can we skip one non-space ifs? (2: yes) */
+ startword = isspace(c) ? 2 : 1;
STARTSTACKSTR(p);
- } else {
- put:
- STPUTC(c, p);
+ continue;
}
+ put:
+ STPUTC(c, p);
}
/* end of do {} while: */
#if ENABLE_ASH_READ_NCHARS
@@ -12643,8 +12654,8 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#endif
STACKSTRNUL(p);
- /* Remove trailing blanks */
- while ((char *)stackblock() <= --p && strchr(ifs, *p) != NULL)
+ /* Remove trailing space ifs chars */
+ while ((char *)stackblock() <= --p && isspace(*p) && strchr(ifs, *p) != NULL)
*p = '\0';
setvar(*ap, stackblock(), 0);
while (*++ap != NULL)