diff mbox series

expand: Fix leading white space regression in ifsbreakup

Message ID ZnbBSnDM7aGUAb5L@gondor.apana.org.au (mailing list archive)
State Under Review
Delegated to: Herbert Xu
Headers show
Series expand: Fix leading white space regression in ifsbreakup | expand

Commit Message

Herbert Xu June 22, 2024, 12:19 p.m. UTC
Martijn Dekker <martijn@inlv.org> wrote:
> As of commit c0674f487c7aec2a3bdf6795cea7e60c9530c360, field splitting is 
> broken. Minimal-ish reproducer:
> 
> $ dash -c 'IFS=:; v=" :: :: "; set $v; echo $#'
> 5
> 
> Expected output: 2
> 
> FYI, this is a nice cross-platform script for testing for field splitting 
> regressions (on dash as well):
> 
> http://web.archive.org/web/20051225040851/http://www.research.att.com/~gsf/public/ifs.sh
> 
> Dash passes this prior to the referenced commit, and fails it after, in 
> informative ways.

Thanks for the report.  This patch should fix the problem:

---8<---
When leading white spaces are detected in ifsbreakup ifsspc needs
to be cleared.

Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: c0674f487c7a ("expand: Support multi-byte characters during field splitting")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/expand.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/expand.c b/src/expand.c
index 6912e39..5285b79 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1282,7 +1282,7 @@  static char *ifsbreakup_slow(struct ifs_state *ifst, struct arglist *arglist,
 		/* Ignore IFS whitespace at start */
 		if (q == ifst->start && ifsspc) {
 			ifst->start = p;
-			return p;
+			goto out_zero_ifsspc;
 		}
 		if (ifst->maxargs > 0 && !--ifst->maxargs) {
 			ifst->r = q;
@@ -1297,6 +1297,7 @@  static char *ifsbreakup_slow(struct ifs_state *ifst, struct arglist *arglist,
 		return p;
 	}
 
+out_zero_ifsspc:
 	ifst->ifsspc = 0;
 	return p;
 }