diff options
author | Iku <iku@yokattana.com> | 2017-02-08 12:14:35 +0100 |
---|---|---|
committer | Iku <iku@yokattana.com> | 2017-02-08 12:19:39 +0100 |
commit | 000265bfbf181c41bd932e4bf48e187df2496cb6 (patch) | |
tree | c0bfb36e7a1b895c96e9957de0d33dee87752cd5 /src/exec.c | |
parent | b9486522575038f93a7dc08ce8860ef7a270ba4b (diff) |
Remove problematic split() function
Major issues with split():
1. It allocates too many array entries
2. It will seek into out of bounds memory
3. It seeds to many nulls
See https://github.com/andmarti1424/sc-im/issues/116 for details.
This commit removes split() and replaces its use with some stdlib
functions.
Tests performed:
- ./scim --half_page_scroll (verify using :set)
- ./scim --half_page_scroll=2 (verify using :set)
- !ls -l
Diffstat (limited to 'src/exec.c')
-rw-r--r-- | src/exec.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -42,18 +42,16 @@ int exec_cmd (char * line) { close(my_pipe[0]); // child doesn't read dup2(my_pipe[1], 1); // redirect stdout - char * l = line; - int j; - l = rtrim(ltrim(line, ' '), ' '); - char ** param = split(l, ' ', 1); - execvp(param[0], param); + int argc = 1; + for (char *p = line; *p; p++) + argc += (*p == ' '); + char **argv = calloc(argc+1, sizeof(char*)); + for (int i = 0; i < argc; i++) + argv[i] = strsep(&line, " "); - for (j=0; param[j]; j++) { - free(param[j]); - } - free(param); - param = NULL; + execvp(argv[0], argv); + free(argv); printf("Error executing command. "); exit(-1); |