From 44757a653cb547ae7b556e8c92629d296d3c1f12 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 22 Jan 2013 16:28:58 +0000 Subject: 30993: fix parameter modifier crash with :wq on empty string --- ChangeLog | 8 +++++++- Src/subst.c | 10 +++++++++- Test/D04parameter.ztst | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cfad073d7..e984c0288 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-01-22 Peter Stephenson + + * 30993: Src/subst.c, Test/D04parameter.ztst: parameter + modifiers :wq operating on an empty string crashed the shell. + The shell isn't supposed to crash. + 2013-01-20 Oliver Kiddle * 30987: Completion/X/Command/_xrandr: only call xrandr when @@ -455,5 +461,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5787 $ +* $Revision: 1.5788 $ ***************************************************** diff --git a/Src/subst.c b/Src/subst.c index 974a8456d..a4df2567f 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3707,6 +3707,11 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) char *y; x = val; + if (!x) { + /* Shouldn't have got here with a NULL string. */ + DPUTS(1, "value is NULL in paramsubst"); + return NULL; + } if (prenum || postnum) x = dopadding(x, prenum, postnum, preone, postone, premul, postmul @@ -4021,7 +4026,10 @@ modify(char **str, char **ptr) all = tmp; t = e; } - *str = all; + if (!all) + *str = dupstring(""); + else + *str = all; } else { switch (c) { diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 01f841218..bea945971 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1544,3 +1544,10 @@ 0:Regression test for shwordsplit with null or unset IFS and quoted array >abc >a b c + + foo= + print ${foo:wq} + print ${:wq} +0:Empty parameter shouldn't cause modifiers to crash the shell +> +> -- cgit 1.4.1