Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: crash (OOB read) in prompt expansion when skipping an unterminated %< / %> / %[ / %D{ inside a conditional
On 20 Nov, todd@xxxxxxxxxxxxx wrote:
> While fuzzing `print -P` with an ASan+UBSan build of current master
> (64159322d0e78f78d17d4c61a87d21256eb532e9), I found a deterministic
> segfault in prompt expansion. It also reproduces on stock macOS system
> zsh 5.9 (/bin/zsh, arm64, no sanitizer).
Thanks for the report.
> Suggested fix
> -------------
>
> Mirror the executed path's guard in the skip switch:
>
> case '<':
> while (*++bv->fm && *bv->fm != '<');
> continue;
The attached patch does exactly this. I also used a basic grep to search
for any other instances of the same pattern and found one case for an
incomplete argument to _arguments. I couldn't reproduce a segfault with
that but could observe it reading beyond the string in a debugger.
Oliver
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index e87eb51a2..8d3cd3a64 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1511,7 +1511,7 @@ parse_cadef(char *nam, char **args)
atype = CAA_OPT;
p++;
} else if (*p == '*') {
- if (*++p != ':') {
+ if (*++p && *p != ':') {
char sav;
for (end = p++; *p && *p != ':'; p++)
diff --git a/Src/prompt.c b/Src/prompt.c
index 7db074da8..555e0f019 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -520,18 +520,18 @@ putpromptchar(int doprint, int endchar)
if (!doprint)
switch(*bv->fm) {
case '[':
- while(idigit(*++bv->fm));
- while(*++bv->fm != ']');
+ while (idigit(*++bv->fm));
+ while (*++bv->fm && *bv->fm != ']');
continue;
case '<':
- while(*++bv->fm != '<');
+ while (*++bv->fm && *bv->fm != '<');
continue;
case '>':
- while(*++bv->fm != '>');
+ while (*++bv->fm && *bv->fm != '>');
continue;
case 'D':
- if(bv->fm[1]=='{')
- while(*++bv->fm != '}');
+ if (bv->fm[1] == '{')
+ while (*++bv->fm && *bv->fm != '}');
continue;
default:
continue;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author