| From 44757a653cb547ae7b556e8c92629d296d3c1f12 Mon Sep 17 00:00:00 2001 |
| From: Peter Stephenson <pws@users.sourceforge.net> |
| Date: Tue, 22 Jan 2013 16:28:58 +0000 |
| Subject: [PATCH] 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/Src/subst.c b/Src/subst.c |
| index 974a845..a4df256 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 01f8412..bea9459 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 |
| +> |
| +> |
| -- |
| 1.8.1.5 |
| |