diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-05-03 10:43:24 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-05-07 16:23:19 +0100 |
commit | f6867efcf895e0010fcdabe0351a5d3fa4a67d89 (patch) | |
tree | a6122e1550d0ae6a43cadbad248617c3c478e0d0 /monkey/dispatch.c | |
parent | 626d37511f968e70c1eac329667e354363a0ebb9 (diff) | |
download | netsurf-f6867efcf895e0010fcdabe0351a5d3fa4a67d89.tar.gz netsurf-f6867efcf895e0010fcdabe0351a5d3fa4a67d89.tar.bz2 |
Fix checking memory allocation return, fixes coverity 1164969
Diffstat (limited to 'monkey/dispatch.c')
-rw-r--r-- | monkey/dispatch.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/monkey/dispatch.c b/monkey/dispatch.c index c186a89ce..ba15fbd13 100644 --- a/monkey/dispatch.c +++ b/monkey/dispatch.c @@ -55,20 +55,34 @@ monkey_process_command(void) char **argv = NULL; char *p, *r = NULL; handle_command_fn fn = NULL; + char **nargv; if (fgets(buffer, PATH_MAX, stdin) == NULL) { netsurf_quit = true; + return; } - - buffer[strlen(buffer)-1] = '\0'; + + /* remove newline */ + buffer[strlen(buffer) - 1] = '\0'; argv = malloc(sizeof *argv); + if (argv == NULL) { + return; + } argc = 1; *argv = buffer; for (p = r = buffer; *p != '\0'; p++) { if (*p == ' ') { - argv = realloc(argv, sizeof(*argv) * (argc + 1)); + nargv = realloc(argv, sizeof(*argv) * (argc + 1)); + if (nargv == NULL) { + /* reallocation of argument vector failed, try using what is + * already processed. + */ + break; + } else { + argv = nargv; + } argv[argc++] = r = p + 1; *p = '\0'; } |