From: Herbert Xu <herbert@gondor.apana.org.au>
To: j.daubert@posteo.de
Cc: Dash <dash@vger.kernel.org>
Subject: [PATCH] shell: Fix unsigned char promotion and truncation
Date: Tue, 21 Oct 2025 21:29:32 +0800 [thread overview]
Message-ID: <aPeKvExPB1HluHly@gondor.apana.org.au> (raw)
In-Reply-To: <df9d5e861c3fc9bf6754fecc113616c1@posteo.de>
On Mon, Oct 20, 2025 at 12:31:03PM +0000, j.daubert@posteo.de 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:
---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 <j.daubert@posteo.de>
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 <herbert@gondor.apana.org.au>
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 <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2025-10-21 13:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 12:31 dash 0.5.13.1: problems with dash as /bin/sh on ARM64 j.daubert
2025-10-21 13:29 ` Herbert Xu [this message]
2025-10-23 11:29 ` [PATCH] shell: Fix unsigned char promotion and truncation Juergen Daubert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aPeKvExPB1HluHly@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
--cc=j.daubert@posteo.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox