summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko2018-07-18 16:02:25 +0200
committerDenys Vlasenko2018-07-18 16:02:25 +0200
commit2e71101e31b8b421cee0107c4136d68b65e3a5d8 (patch)
tree7133a7b78605cdf71bfde5a8066c4c12918f9184 /shell
parent8b08d5a502adec2067e3ebf7f27513f75b0b95e8 (diff)
downloadbusybox-2e71101e31b8b421cee0107c4136d68b65e3a5d8.zip
busybox-2e71101e31b8b421cee0107c4136d68b65e3a5d8.tar.gz
hush: fix 'x=; echo ${x:-"$@"}' producing 'BUG in varexp2' message
function old new delta expand_string_to_string 126 128 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 534fabb..da10a09 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6529,13 +6529,20 @@ static char *expand_string_to_string(const char *str, int EXP_flags, int do_unba
argv[0] = (char*)str;
argv[1] = NULL;
list = expand_variables(argv, EXP_flags | EXP_FLAG_SINGLEWORD);
- if (HUSH_DEBUG)
- if (!list[0] || list[1])
- bb_error_msg_and_die("BUG in varexp2");
- /* actually, just move string 2*sizeof(char*) bytes back */
- overlapping_strcpy((char*)list, list[0]);
- if (do_unbackslash)
- unbackslash((char*)list);
+ if (!list[0]) {
+ /* Example where it happens:
+ * x=; echo ${x:-"$@"}
+ */
+ ((char*)list)[0] = '\0';
+ } else {
+ if (HUSH_DEBUG)
+ if (list[1])
+ bb_error_msg_and_die("BUG in varexp2");
+ /* actually, just move string 2*sizeof(char*) bytes back */
+ overlapping_strcpy((char*)list, list[0]);
+ if (do_unbackslash)
+ unbackslash((char*)list);
+ }
debug_printf_expand("string_to_string=>'%s'\n", (char*)list);
return (char*)list;
}