diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-18 13:37:09 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-18 13:37:09 +0200 |
| commit | 5c2c2916fc9254793f711503030ba997112db6e4 (patch) | |
| tree | 83efb66f678cc63cdcfc3d5742d3d52dc6ee4388 | |
| parent | 2bdec03def3054bbd80d5fd23e9bb0c026f85fc4 (diff) | |
hush: do not SEGV on if { echo foo; } then { echo bar; } fi
For some reason, it was only happening in interactive use
function old new delta
initialize_context 39 54 +15
parse_stream 3077 3063 -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-14) Total: 1 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | shell/hush.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index f776a6468..1495db373 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -4202,6 +4202,10 @@ static void initialize_context(struct parse_context *ctx) * ctx->command = &ctx->pipe->cmds[0]; */ done_command(ctx); + /* If very first arg is "" or '', ctx.word.data may end up NULL. + * Prevent this: + */ + ctx->word.data = xzalloc(1); /* start as "", not as NULL */ } /* If a reserved word is found and processed, parse context is modified @@ -5840,11 +5844,6 @@ static struct pipe *parse_stream(char **pstring, enable_all_aliases(); initialize_context(&ctx); - /* If very first arg is "" or '', ctx.word.data may end up NULL. - * Preventing this: - */ - ctx.word.data = xzalloc(1); /* start as "", not as NULL */ - /* We used to separate words on $IFS here. This was wrong. * $IFS is used only for word splitting when $var is expanded, * here we should use blank chars as separators, not $IFS |
