[bash-5.3 patch 19/20] OOB global read in parameter_brace_expand via ${#
From:
abderrahmane sebban
Subject:
[bash-5.3 patch 19/20] OOB global read in parameter_brace_expand via ${#<high-byte>}
Date:
Mon, 5 Oct 2026 21:13:16 +0000
Hi Chet,
Patch 19 (commit 549639c) changed legal_variable_starter() in general.h
to index sh_syntaxtab[] directly, but without the (unsigned char) cast
that the sibling macros in syntax.h use (shellmeta, shellbreak, shellquote).
The one caller that passes a signed char without pre-casting --
subst.c:9798 in parameter_brace_expand() -- now reads out of bounds of
sh_syntaxtab[] for any input byte in 0x80-0xFF.
Minimal reproducer:
printf 'echo ${#\xff}\n' | ./bash --norc --noprofile
AddressSanitizer report (bash-5.3 patch 20, built with -fsanitize=address):
ERROR: AddressSanitizer: global-buffer-overflow
READ of size 4 at 0x...
#0 parameter_brace_expand subst.c:9798
#1 param_expand subst.c:10800
#2 expand_word_internal subst.c:11531
#3 shell_expand_word_list subst.c:13089
#4 expand_word_list_internal subst.c:13256
#5 expand_words subst.c:12584
#6 execute_simple_command execute_cmd.c:4617
0x... is located 4 bytes before global variable 'sh_syntaxtab'
(int[256]) defined in syntax.c.
Impact: 4-byte global out-of-bounds read, reachable from any shell input
containing ${#X...} where the first byte of X has the high bit set.
Information disclosure of adjacent globals; no code execution.
Not present in released bash-5.3 or bash-5.2. Introduced by patch 19
(2026-09-15), still present in patch 20.
Suggested fix:
--- a/general.h
+++ b/general.h
@@ -114,8 +114,8 @@
-#define legal_variable_starter(c) (sh_syntaxtab[c] & CNAMESTART)
-#define legal_variable_char(c) (sh_syntaxtab[c] & CNAME)
+#define legal_variable_starter(c) (sh_syntaxtab[(unsigned char)(c)] &
CNAMESTART)
+#define legal_variable_char(c) (sh_syntaxtab[(unsigned char)(c)] &
CNAME)
Rebuilt with the above patch; ASan is quiet and ${#var} still works.
Thanks,
Abderrahmane Sebban