diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-06-15 18:57:12 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2022-06-15 18:57:12 -0400 |
commit | a54eb317c73422f72487fac33ac7813f7b518e7e (patch) | |
tree | bc0ba097182159ed75a1db384e46fcb31b9dbf20 /src/main.c | |
parent | e63ef9264526ebb2ec0f617199c462df81ff2d9b (diff) | |
download | cleanpath-a54eb317c73422f72487fac33ac7813f7b518e7e.tar.gz |
Fix segfault on empty --env/-E and --sep arguments
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -39,6 +39,10 @@ static int is_valid_arg(char **args, char *s) { static char *getenv_ex(char *s) { char *key, *key_end; char *env_var; + if (!s) { + return NULL; + } + key = strdup(s); if (!key) { return NULL; @@ -205,12 +209,17 @@ int main(int argc, char *argv[], char *arge[]) { if (ARGM("--sep") || ARGM("-s")) { i++; sep = argv[i]; + if (!sep) { + fprintf(stderr, "%s requires an argument\n", argv[i - 1]); + exit(1); + } continue; } if (ARGM("--env") || ARGM("-E")) { i++; sys_var = getenv_ex(argv[i]); if (!sys_var) { + fprintf(stderr, "%s requires an argument\n", argv[i - 1]); exit(1); } continue; |