klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
Commit-ID: 4dc603d0fe5a997d8bbd5048b229d655e6549ced Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=4dc603d0fe5a997d8bbd5048b229d655e6549ced Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Wed, 8 Oct 2014 15:24:23 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty [ dash commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ] Currently we do not field-split $@/$* when it isn't quoted and IFS is set but empty. This is obviously wrong. This patch fixes this. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/expand.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/usr/dash/expand.c b/usr/dash/expand.c index c4d52606..add952b7 100644 --- a/usr/dash/expand.c +++ b/usr/dash/expand.c @@ -116,7 +116,7 @@ STATIC const char *subevalvar(char *, char *, int, int, int, int, int); STATIC char *evalvar(char *, int); STATIC size_t strtodest(const char *, const char *, int); STATIC void memtodest(const char *, size_t, const char *, int); -STATIC ssize_t varvalue(char *, int, int); +STATIC ssize_t varvalue(char *, int, int, int *); STATIC void expandmeta(struct strlist *, int); #ifdef HAVE_GLOB STATIC void addglob(const glob_t *); @@ -722,6 +722,7 @@ evalvar(char *p, int flag) ssize_t varlen; int easy; int quoted; + int nulonly; varflags = *p++; subtype = varflags & VSTYPE; @@ -732,11 +733,12 @@ evalvar(char *p, int flag) quoted = flag & EXP_QUOTED; var = p; easy = (!quoted || (*var == '@' && shellparam.nparam)); + nulonly = easy; startloc = expdest - (char *)stackblock(); p = strchr(p, '=') + 1; again: - varlen = varvalue(var, varflags, flag); + varlen = varvalue(var, varflags, flag, &nulonly); if (varflags & VSNUL) varlen--; @@ -787,7 +789,7 @@ vsplus: if (!easy) goto end; record: - recordregion(startloc, expdest - (char *)stackblock(), quoted); + recordregion(startloc, expdest - (char *)stackblock(), nulonly); goto end; } @@ -892,7 +894,7 @@ strtodest(p, syntax, quotes) */ STATIC ssize_t -varvalue(char *name, int varflags, int flags) +varvalue(char *name, int varflags, int flags, int *nulonly) { int num; char *p; @@ -907,7 +909,8 @@ varvalue(char *name, int varflags, int flags) int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL; ssize_t len = 0; - sep = quoted ? ((flags & EXP_FULL) << CHAR_BIT) : 0; + sep = *nulonly ? (flags & EXP_FULL) << CHAR_BIT : 0; + *nulonly = 0; syntax = quoted ? DQSYNTAX : BASESYNTAX; switch (*name) { @@ -938,15 +941,16 @@ numvar: expdest = p; break; case '@': - if (sep) + if (quoted) goto param; /* fall through */ case '*': - sep = ifsset() ? ifsval()[0] : ' '; + sep |= ifsset() ? ifsval()[0] : ' '; param: if (!(ap = shellparam.p)) return -1; sepc = sep; + *nulonly = !sepc; while ((p = *ap++)) { len += strtodest(p, syntax, quotes);
Maybe Matching Threads
- [klibc:update-dash] [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
- [klibc:update-dash] expand: Fix ghost fields with unquoted $@/$*
- [klibc:update-dash] [EXPAND] Optimise nulonly away and just use quoted as before
- [klibc:update-dash] dash: expand: Fix ghost fields with unquoted $@/$*
- [klibc:update-dash] dash: [EXPAND] Optimise nulonly away and just use quoted as before