[PATCH] parser: Do not display prompts in expandstr
Herbert Xu <[email protected]> Wed, 27 Aug 2025 17:13:02 +0800
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
Aleksander Ushakov <[email protected]> wrote: > > Hello Dash maintainers, > > I encountered a bug in Dash in commit fd725b7a75 and would like to > report it. The details are provided below. > The target crashed when reading from memory after it has been freed. > ==131==ERROR: AddressSanitizer: heap-buffer-overflow on address > 0x5020000004f5 at pc 0x60bd0214d131 bp 0x7fff45c03700 sp 0x7fff45c02eb0 > READ of size 2 at 0x5020000004f5 thread T0 > #0 0x60bd0214d130 in __interceptor_strlen > ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:389 > #1 0x60bd02239fee in setinputstring /upstream/dash/src/input.c:593 > #2 0x60bd0226936c in expandstr /upstream/dash/src/parser.c:1739 > #3 0x60bd02215e18 in evalcommand /upstream/dash/src/eval.c:881 > #4 0x60bd0220d9f0 in evaltree /upstream/dash/src/eval.c:305 > #5 0x60bd0224b2eb in cmdloop /upstream/dash/src/main.c:246 > #6 0x60bd0212643c in main /upstream/dash/src/main.c:180 > > 0x5020000004f5 is located 0 bytes to the right of 5-byte region > [0x5020000004f0,0x5020000004f5) > allocated by thread T0 here: > #0 0x60bd021bb38f in __interceptor_malloc > ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69 > #1 0x60bd0224c728 in ckmalloc /upstream/dash/src/memalloc.c:66 I couldn't reproduce this, but I did notice that PS2 was being incorrectly shown during PS4 expansion: ---8<--- Set needprompt to zero as it may have been set by the caller. It is safe to do so here as the only calls to expandstr within the parser set needprompt to zero already. Reported-by: Aleksander Ushakov <[email protected]> Signed-off-by: Herbert Xu <[email protected]> diff --git a/src/parser.c b/src/parser.c index aecc18f..a3b004b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1742,6 +1742,7 @@ expandstr(const char *ps) heredoclist = NULL; saveprompt = doprompt; doprompt = 0; + needprompt = 0; result = ps; savehandler = handler; if (unlikely(err = setjmp(jmploc.loc))) -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt