[PATCH] expand: Fix leading white space regression in ifsbreakup

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
Martijn Dekker <[email protected]> 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 <[email protected]>
Fixes: c0674f487c7a ("expand: Support multi-byte characters during field splitting")
Signed-off-by: Herbert Xu <[email protected]>
---
 src/expand.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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;
 }
-- 
2.39.2
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.