summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-15 12:42:34 -0400
committerJakob Kaivo <jkk@ung.org>2019-03-15 12:42:34 -0400
commit4f02abda506190ca020f7758a2177aa6c5035c64 (patch)
treef97c2fbdf3e08ab7bdd9b0f4035d7b69976b17de /parse.c
parentc4593efbced8d1d5cae004975f6bd7b91904810c (diff)
really don't crash on empty input
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 7763d26..39b3502 100644
--- a/parse.c
+++ b/parse.c
@@ -17,6 +17,8 @@
*
*/
+#define _XOPEN_SOURCE 700
+
#include "sh.h"
#include <ctype.h>
#include <errno.h>
@@ -63,12 +65,17 @@ struct command *sh_parse(const char *cmdline)
start++;
}
- char *end = l + strlen(l) - 1;
+ char *end = l + strlen(l);
while (isspace(*end) && end > start) {
*end = '\0';
end--;
}
+ if (end <= start) {
+ free(l);
+ return NULL;
+ }
+
struct command *cmd = calloc(1, sizeof(*cmd));
if (cmd == NULL) {
/* TODO: should probably crash here */