diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/core/environment.c | 9 | ||||
| -rw-r--r-- | src/lib/core/log.c | 2 | ||||
| -rw-r--r-- | src/lib/core/str.c | 9 | ||||
| -rw-r--r-- | src/lib/core/strlist.c | 10 | ||||
| -rw-r--r-- | src/lib/core/utils.c | 3 |
5 files changed, 26 insertions, 7 deletions
diff --git a/src/lib/core/environment.c b/src/lib/core/environment.c index 4623db8..b4ab66e 100644 --- a/src/lib/core/environment.c +++ b/src/lib/core/environment.c @@ -445,9 +445,14 @@ void runtime_set(RuntimeEnv *env, const char *_key, char *_value) { */ void runtime_apply(RuntimeEnv *env) { for (size_t i = 0; i < strlist_count(env); i++) { - char **pair = split(strlist_item(env, i), "=", 1); + const char *item = strlist_item(env, i); + if (!item) { + SYSERROR("failed to read from env list"); + return; + } + char **pair = split((char *) item, "=", 1); if (!pair) { - SYSERROR("unable to allocate memory for runtime_apply"); + SYSERROR("unable to allocate memory for key/value pair"); return; } setenv(pair[0], pair[1], 1); diff --git a/src/lib/core/log.c b/src/lib/core/log.c index b1cab4c..8f24702 100644 --- a/src/lib/core/log.c +++ b/src/lib/core/log.c @@ -89,7 +89,7 @@ int log_msgv(FILE *stream, const struct ExecPoint ep, const char *preface_color, SYSERROR("\nvfprintf failed"); return len; } - fprintf(stderr, LINE_SEP); + fprintf(stream, LINE_SEP); return len; } diff --git a/src/lib/core/str.c b/src/lib/core/str.c index a04293f..84a325b 100644 --- a/src/lib/core/str.c +++ b/src/lib/core/str.c @@ -171,6 +171,10 @@ char *join(char **arr, const char *separator) { total_bytes += (records * strlen(separator)) + 1; result = (char *)calloc(total_bytes, sizeof(char)); + if (!result) { + return NULL; + } + for (int i = 0; i < records; i++) { safe_strncat(result, arr[i], total_bytes); if (i < (records - 1)) { @@ -225,6 +229,11 @@ char *join_ex(char *separator, ...) { // Generate output string result = calloc(size + 1, sizeof(char)); + if (!result) { + guard_array_free_by_count(argv, argc); + return NULL; + } + for (size_t i = 0; i < argc; i++) { // Append argument to string safe_strncat(result, argv[i], size + 1); // no -1 because +1 above diff --git a/src/lib/core/strlist.c b/src/lib/core/strlist.c index 60f3a1f..e209bdf 100644 --- a/src/lib/core/strlist.c +++ b/src/lib/core/strlist.c @@ -171,11 +171,15 @@ int strlist_contains(struct StrList *pStrList, const char *value, size_t *index_ for (size_t i = 0; i < strlist_count(pStrList); i++) { const char *item = strlist_item(pStrList, i); if (!item) { - *index_of = 0; + if (index_of) { + *index_of = 0; + } break; } - if (!strcmp(item, value)) { - *index_of = i; + if (strstr(item, value)) { + if (index_of) { + *index_of = i; + } return 1; } } diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index 152c5c5..31208ad 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -611,6 +611,7 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro snprintf(cmd, sizeof(cmd), "%s %s %s", pretty_print_prog, pretty_print_args, filename); result = shell_output(cmd, &status); if (status || !result) { + guard_free(result); return status; } @@ -920,7 +921,7 @@ int env_manipulate_pathstr(const char *key, char *path, int mode) { } if (mode & PM_ONCE) { - if (!strstr(system_path_old, path)) { + if (strstr(system_path_old, path)) { guard_free(system_path_new); return 0; } |
