Browse Source

Catch some bad shell syntax

K. Lange 4 years ago
parent
commit
6ac1370025
1 changed files with 9 additions and 0 deletions
  1. 9 0
      apps/sh.c

+ 9 - 0
apps/sh.c

@@ -835,6 +835,10 @@ _done:
 		}
 
 		if (!strcmp(c, PIPE_TOKEN)) {
+			if (arg_starts[cmdi] == &argv[i]) {
+				fprintf(stderr, "Syntax error: Unexpected pipe token\n");
+				return 2;
+			}
 			argv[i] = 0;
 			i++;
 			cmdi++;
@@ -923,6 +927,11 @@ _nope:
 
 	list_free(args);
 
+	if (!*arg_starts[cmdi]) {
+		fprintf(stderr, "Syntax error: Unexpected end of input\n");
+		return 2;
+	}
+
 	char * cmd = *arg_starts[0];
 	tokenid = i;