Patchwork [U-Boot,2/2] hush: Prevent pipe errors from being silently ignored

login
register
mail settings
Submitter Joe Hershberger
Date Nov. 8, 2012, 8:15 p.m.
Message ID <1352405756-401-2-git-send-email-joe.hershberger@ni.com>
Download mbox | patch
Permalink /patch/197876/
State Rejected
Delegated to: Tom Rini
Headers show

Comments

Joe Hershberger - Nov. 8, 2012, 8:15 p.m.
Disallow commands like "&& true" and "false && || true"

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---
 common/hush.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Patch

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);