From patchwork Thu Nov 8 20:15:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot,2/2] hush: Prevent pipe errors from being silently ignored From: Joe Hershberger X-Patchwork-Id: 197876 Message-Id: <1352405756-401-2-git-send-email-joe.hershberger@ni.com> To: u-boot@lists.denx.de Cc: Tom Rini , Joe Hershberger Date: Thu, 8 Nov 2012 14:15:56 -0600 Disallow commands like "&& true" and "false && || true" Signed-off-by: Joe Hershberger --- common/hush.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/hush.c b/common/hush.c index 43edcfa..1427557 100644 --- a/common/hush.c +++ b/common/hush.c @@ -1805,6 +1805,11 @@ static int run_list_real(struct pipe *pi) } rmode = pi->r_mode; debug_printf("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", rmode, if_code, next_if_code, skip_more_in_this_rmode); + if ((pi->followup == PIPE_OR || pi->followup == PIPE_AND) && + (pi->num_progs == 0 || pi->next->num_progs == 0)) { + puts("Pipe syntax error\n"); + return -1; + } if (rmode == skip_more_in_this_rmode && flag_skip) { if (pi->followup == PIPE_SEQ) flag_skip=0; continue; @@ -2940,6 +2945,7 @@ int parse_stream(o_string *dest, struct p_context *ctx, redir_type redir_style; #endif int next; + int ret; /* Only double-quote state is handled in the state variable dest->quote. * A single-quote triggers a bypass of the main loop until its mate is @@ -3056,7 +3062,13 @@ int parse_stream(o_string *dest, struct p_context *ctx, #endif case ';': done_word(dest, ctx); - done_pipe(ctx,PIPE_SEQ); + ret = done_pipe(ctx, PIPE_SEQ); + if (ret && + (ctx->last_followup == PIPE_AND || + ctx->last_followup == PIPE_OR)) { + puts("Pipe syntax error\n"); + return 1; + } break; case '&': done_word(dest, ctx);