[U-Boot] [PATCH 2/2] hush: Prevent pipe errors from being silently ignored
Joe Hershberger
joe.hershberger at ni.com
Thu Nov 8 21:15:56 CET 2012
Disallow commands like "&& true" and "false && || true"
Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---
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);
--
1.7.11.5
More information about the U-Boot
mailing list