diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-19 23:07:51 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-19 23:07:51 +0000 |
commit | dcd78c4d0ff71a36d5c88953a62f5df6a4f31a9c (patch) | |
tree | 0fe10d42d2e0a35a4231aa81314691a972098819 /shell/hush.c | |
parent | 3798db58cfa0e939d0fc1822c9864355c1422cd0 (diff) | |
download | busybox-w32-dcd78c4d0ff71a36d5c88953a62f5df6a4f31a9c.tar.gz busybox-w32-dcd78c4d0ff71a36d5c88953a62f5df6a4f31a9c.tar.bz2 busybox-w32-dcd78c4d0ff71a36d5c88953a62f5df6a4f31a9c.zip |
hush: fix "export not_yet_defined_var", fix parsing of "cmd | }"
corner case; improve hush_leaktool.sh;
fix some false positives in testsuite
function old new delta
builtin_export 191 206 +15
parse_stream 2196 2200 +4
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/shell/hush.c b/shell/hush.c index c542b7dd9..2c2750fc8 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4459,10 +4459,6 @@ static int done_word(o_string *word, struct parse_context *ctx) | |||
4459 | } | 4459 | } |
4460 | } | 4460 | } |
4461 | command->argv = add_string_to_strings(command->argv, xstrdup(word->data)); | 4461 | command->argv = add_string_to_strings(command->argv, xstrdup(word->data)); |
4462 | //SEGV, but good idea. | ||
4463 | // command->argv = add_string_to_strings(command->argv, word->data); | ||
4464 | // word->data = NULL; | ||
4465 | // word->length = 0; | ||
4466 | debug_print_strings("word appended to argv", command->argv); | 4462 | debug_print_strings("word appended to argv", command->argv); |
4467 | } | 4463 | } |
4468 | 4464 | ||
@@ -5481,14 +5477,16 @@ static struct pipe *parse_stream(char **pstring, | |||
5481 | * } is an ordinary char in this case, even inside { cmd; } | 5477 | * } is an ordinary char in this case, even inside { cmd; } |
5482 | * Pathological example: { ""}; } should exec "}" cmd | 5478 | * Pathological example: { ""}; } should exec "}" cmd |
5483 | */ | 5479 | */ |
5484 | if (ch == '}' | 5480 | if (ch == '}') { |
5485 | && !(IS_NULL_PIPE(ctx.pipe) | 5481 | if (!IS_NULL_CMD(ctx.command) /* cmd } */ |
5486 | && IS_NULL_CMD(ctx.command) | 5482 | || dest.length != 0 /* word} */ |
5487 | && dest.length == 0 | 5483 | || dest.o_quoted /* ""} */ |
5488 | && !dest.o_quoted | 5484 | ) { |
5489 | ) | 5485 | goto ordinary_char; |
5490 | ) { | 5486 | } |
5491 | goto ordinary_char; | 5487 | if (!IS_NULL_PIPE(ctx.pipe)) /* cmd | } */ |
5488 | goto skip_end_trigger; | ||
5489 | /* else: } does terminate a group */ | ||
5492 | } | 5490 | } |
5493 | 5491 | ||
5494 | if (end_trigger && end_trigger == ch | 5492 | if (end_trigger && end_trigger == ch |
@@ -5531,6 +5529,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5531 | return ctx.list_head; | 5529 | return ctx.list_head; |
5532 | } | 5530 | } |
5533 | } | 5531 | } |
5532 | skip_end_trigger: | ||
5534 | if (is_ifs) | 5533 | if (is_ifs) |
5535 | continue; | 5534 | continue; |
5536 | 5535 | ||
@@ -6420,12 +6419,11 @@ static int builtin_export(char **argv) | |||
6420 | } | 6419 | } |
6421 | 6420 | ||
6422 | do { | 6421 | do { |
6423 | const char *value; | ||
6424 | char *name = *argv; | 6422 | char *name = *argv; |
6425 | 6423 | ||
6426 | value = strchr(name, '='); | 6424 | /* So far we do not check that name is valid */ |
6427 | if (!value) { | 6425 | if (strchr(name, '=') == NULL) { |
6428 | /* They are exporting something without a =VALUE */ | 6426 | /* Exporting a name without a =VALUE */ |
6429 | struct variable *var; | 6427 | struct variable *var; |
6430 | 6428 | ||
6431 | var = get_local_var(name); | 6429 | var = get_local_var(name); |
@@ -6433,12 +6431,19 @@ static int builtin_export(char **argv) | |||
6433 | var->flg_export = 1; | 6431 | var->flg_export = 1; |
6434 | debug_printf_env("%s: putenv '%s'\n", __func__, var->varstr); | 6432 | debug_printf_env("%s: putenv '%s'\n", __func__, var->varstr); |
6435 | putenv(var->varstr); | 6433 | putenv(var->varstr); |
6434 | continue; | ||
6436 | } | 6435 | } |
6437 | /* bash does not return an error when trying to export | 6436 | /* Exporting non-existing variable. |
6438 | * an undefined variable. Do likewise. */ | 6437 | * bash does not put it in environment, |
6439 | continue; | 6438 | * but remembers that it is exported, |
6439 | * and does put it in env when it is set later. | ||
6440 | * We just set it to "" and export. */ | ||
6441 | name = xasprintf("%s=", name); | ||
6442 | } else { | ||
6443 | /* Exporting VAR=VALUE */ | ||
6444 | name = xstrdup(name); | ||
6440 | } | 6445 | } |
6441 | set_local_var(xstrdup(name), 1, 0); | 6446 | set_local_var(name, 1, 0); |
6442 | } while (*++argv); | 6447 | } while (*++argv); |
6443 | 6448 | ||
6444 | return EXIT_SUCCESS; | 6449 | return EXIT_SUCCESS; |