aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2026-06-22 11:52:45 -0400
committerGitHub <noreply@github.com>2026-06-22 11:52:45 -0400
commit70c1ba3962166853fc7a1e4f2bb1d637104312b1 (patch)
tree98ffb40c90a2016aff436134e14eed1f9a401cb5 /src/lib
parent582744998b624cada2293a533e0cce5720433454 (diff)
downloadstasis-70c1ba3962166853fc7a1e4f2bb1d637104312b1.tar.gz
General fixes (#149)HEAD1.7.1master
* Fix missing LF * Return when item is NULL * Explicitly state error condition * strlist_contains: Allow index result argument to be NULL * BUGFIX: strlist_contains now uses strstr instead of strcmp * The match was never intended to be exact * BUGFIX: log_msgv now prints a LF to the same stream as the message * BUGFIX: env_manipulate_pathstr PM_ONCE logic did opposite of what was intended * When strstr finds the path in the system path, it's supposed to free the new system path and exit. In this case it was freeing the path when the path wasn't found that lead to several instances of PATH not being updated correctly * Free result when shell_output fails * join: Fix segfault on memory error * join_ex: Fix leak on memory error * Initialize installer_url and python_override_version to zero * Remove redundant calls to memset
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/core/environment.c9
-rw-r--r--src/lib/core/log.c2
-rw-r--r--src/lib/core/str.c9
-rw-r--r--src/lib/core/strlist.c10
-rw-r--r--src/lib/core/utils.c3
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;
}