Re: [PATCH] shell: Fix unsigned char promotion and truncation

Juergen Daubert <[email protected]> Thu, 23 Oct 2025 11:29:43 +0000
Newsgroups org.kernel.vger.dash
Message-ID <aPoRpuQWtKeQq5T-@jue>
On Tue, Oct 21, 2025 at 09:29:32PM +0800, Herbert Xu wrote:
> On Mon, Oct 20, 2025 at 12:31:03PM +0000, [email protected] wrote:
> > We are using dash 0.5.13.1 as /bin/sh and running into several build
> > problems on ARM64,
> > for example curl:
> 
> Thanks for the report!
> 
> I can reproduce this and it appears to be a couple of instances of
> incorrect unsigned char (the default on arm64) promotion.
> 
> Please try this patch:

Thanks for the quick fix!

We've tested 0.5.13.1 together with that patch by building a lot of
important programs [1] with dash as /bin/sh and everything works fine 
now on x86_64 and ARM64. 

IMO we are at a stable point in the dash development again, looking
forward to see 0.5.14 ;)

Thanks again
Juergen


[1] https://git.crux.nu/ports/core


> 
> ---8<---
> When a char is promoted to an int, it needs to be signed as otherwise
> comparisons on it may fail.  Alternatively, an integer needs to be
> truncated to char before comparing it against another char.
> 
> Reported-by: Juergen Daubert <[email protected]> 
> Fixes: e878137f63e6 ("expand: Do not call rmescapes in expari")
> Fixes: c5bf9702ea11 ("expand: Add multi-byte support to pmatch")
> Fixes: 8f01c3796f0f ("[PARSER] Add FAKEEOFMARK for expandstr")
> Signed-off-by: Herbert Xu <[email protected]>
> 
> diff --git a/src/expand.c b/src/expand.c
> index 912384d..8c8bf0e 100644
> --- a/src/expand.c
> +++ b/src/expand.c
> @@ -1914,7 +1914,7 @@ static int pmatch(char *pattern, const char *string)
>  			if (c == '?' || c == '[')
>  				c = CTLESC;
>  			for (;;) {
> -				if (c != CTLESC) {
> +				if (c != (char)CTLESC) {
>  					/* Stop should be null-terminated
>  					 * as it is passed as a string to
>  					 * strpbrk(3).
> @@ -1985,7 +1985,7 @@ static int pmatch(char *pattern, const char *string)
>  					p++;
>  					if (*p == (char)CTLESC)
>  						p++;
> -					else if (*p == CTLMBCHAR) {
> +					else if (*p == (char)CTLMBCHAR) {
>  						mbp = mbnext(p);
>  						p += mbp & 0xff;
>  						p += mbp >> 8;
> diff --git a/src/parser.c b/src/parser.c
> index eb402a7..5714958 100644
> --- a/src/parser.c
> +++ b/src/parser.c
> @@ -1240,7 +1240,7 @@ checkend: {
>  
>  		markloc = out - (char *)stackblock();
>  		for (p = eofmark; STPUTC(c, out), *p; p++) {
> -			if (c != *p)
> +			if (c != (signed char)*p)
>  				goto more_heredoc;
>  
>  			c = pgetc();
> -- 
> Email: Herbert Xu <[email protected]>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
>