aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli/stasis/stasis_main.c21
-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
6 files changed, 31 insertions, 23 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c
index e660f6b..ef7bf26 100644
--- a/src/cli/stasis/stasis_main.c
+++ b/src/cli/stasis/stasis_main.c
@@ -521,32 +521,21 @@ static void transfer_artifacts(struct Delivery *ctx) {
}
}
-int main(int argc, char *argv[]) {
- struct Delivery ctx;
- struct Process proc = {
- .f_stdout = "",
- .f_stderr = "",
- .redirect_stderr = 0,
- };
+int main(const int argc, char *argv[]) {
+ struct Delivery ctx = {0};
+
char env_name[STASIS_NAME_MAX] = {0};
char env_name_testing[STASIS_NAME_MAX] = {0};
char *delivery_input = NULL;
char *config_input = NULL;
- char installer_url[PATH_MAX];
- char python_override_version[STASIS_NAME_MAX];
+ char installer_url[PATH_MAX] = {0};
+ char python_override_version[STASIS_NAME_MAX] = {0};
int user_disabled_docker = false;
globals.cpu_limit = get_cpu_count();
if (globals.cpu_limit > 1) {
globals.cpu_limit--; // max - 1
}
- memset(env_name, 0, sizeof(env_name));
- memset(env_name_testing, 0, sizeof(env_name_testing));
- memset(installer_url, 0, sizeof(installer_url));
- memset(python_override_version, 0, sizeof(python_override_version));
- memset(&proc, 0, sizeof(proc));
- memset(&ctx, 0, sizeof(ctx));
-
setup_sysconfdir();
int c;
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;
}