[PATCH] parser: Clamp backslash-c sequences to 7 bits

Herbert Xu <[email protected]> Sun, 7 Jun 2026 20:57:41 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
On Sat, Jun 06, 2026 at 02:34:07PM -0700, Nathan Mills wrote:
>
> ** Crash #0: illegal instruction **
> Base64'd:
> 
> JCQkXERdLwovCiQgJC4kJCS4uAwkJFwyXU//AD8KJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQk
> JCUlJCQkJCQnJCQkuLgMJCRcY8TE0V0vCiQkJCclJSW4uAwkJFxEXS8KJCQkJyQkJCQX
> 
> Minimal base64'd:
> 
> JCdcY8Qn
> 
> Minimal reproducer: src/dash -c $'$'\''\\c\xC4'\'''

This is caused by dollar-sq with \c producing 8-bit characters:

---8<---
Ensure that \c does not produce an 8-bit character by clamping
it with 0x7f.

Reported-by: Nathan Mills <[email protected]>
Fixes: 776424a8f915 ("parser: Add dollar single quote")
Signed-off-by: Herbert Xu <[email protected]>

diff --git a/src/parser.c b/src/parser.c
index 412e876..65c5fd6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -968,7 +969,7 @@ static char *dollarsq_escape(char *out)
 
 		p += !((c ^ *p) | (c ^ '\\'));
 
-		conv_ch = (c & ~((c & 0x40) >> 1)) ^ 0x40;
+		conv_ch = (c & ~((c & 0x40) >> 1) & 0x7f) ^ 0x40;
 		USTPUTC(conv_ch, out);
 	}
 
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt