Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Zsh parser segmentation fault in putpromptchar putpromptchar at prompt.c



On Mon, 8 May 2017 13:42:46 -0500
Eduardo Bustamante <dualbus@xxxxxxxxx> wrote:
> dualbus@debian:~/bash-fuzzing/zsh-parser$ base64 segfault
> JHsoJVUpWS0lKHZ9
> 
> dualbus@debian:~/bash-fuzzing/zsh-parser$ md5sum segfault
> 0d79a8c613315f32a453d5aa07a7de65  segfault
> 
> dualbus@debian:~/bash-fuzzing/zsh-parser$ cat -v segfault
> ${(%U)Y-%(v}

The test for psvar is wrong if it's empty.

pws

diff --git a/Src/prompt.c b/Src/prompt.c
index 29e006e..c478e69 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -399,7 +399,7 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 			test = 1;
 		    break;
 		case 'V':
-		    if (arrlen_ge(psvar, arg)) {
+		    if (psvar && *psvar && arrlen_ge(psvar, arg)) {
 			if (*psvar[(arg ? arg : 1) - 1])
 			    test = 1;
 		    }
diff --git a/Test/D01prompt.ztst b/Test/D01prompt.ztst
index 0818728..11f18dc 100644
--- a/Test/D01prompt.ztst
+++ b/Test/D01prompt.ztst
@@ -209,3 +209,7 @@
  print -P -f '%%Sfoo%%s\n' bar
 0:print -P -f
 >%Sfoo%s
+
+  print ${(%U)Y-%(v}
+0:Regression test for test on empty psvar
+>



Messages sorted by: Reverse Date, Date, Thread, Author