aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-09-30 12:39:09 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-09-30 12:39:09 -0400
commit73219c6e26a4847b3429318148918b78f6452ac1 (patch)
tree4061e6466311a5d128b472792617e5b6e4b1fac3
parentd1642b3514f23be90e8292fce4569990c813d8eb (diff)
downloadstasis-73219c6e26a4847b3429318148918b78f6452ac1.tar.gz
Allocate runner_cmd using asprintf
-rw-r--r--src/delivery_test.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/delivery_test.c b/src/delivery_test.c
index 959a99b..804cbc9 100644
--- a/src/delivery_test.c
+++ b/src/delivery_test.c
@@ -121,7 +121,7 @@ void delivery_tests_run(struct Delivery *ctx) {
continue;
}
- char runner_cmd[0xFFFF] = {0};
+ char *runner_cmd = NULL;
char pool_name[100] = "parallel";
struct MultiProcessingTask *task = NULL;
int selected = PARALLEL;
@@ -131,18 +131,23 @@ void delivery_tests_run(struct Delivery *ctx) {
strcpy(pool_name, "serial");
}
- sprintf(runner_cmd, runner_cmd_fmt, cmd);
+ if (asprintf(&runner_cmd, runner_cmd_fmt, cmd) < 0) {
+ SYSERROR("Unable to allocate memory for runner command: %s", strerror(errno));
+ exit(1);
+ }
task = mp_pool_task(pool[selected], test->name, destdir, runner_cmd);
if (!task) {
SYSERROR("Failed to add task to %s pool: %s", pool_name, runner_cmd);
popd();
if (!globals.continue_on_error) {
+ guard_free(runner_cmd);
tpl_free();
delivery_free(ctx);
globals_free();
}
exit(1);
}
+ guard_free(runner_cmd);
guard_free(cmd);
popd();
@@ -161,7 +166,8 @@ void delivery_tests_run(struct Delivery *ctx) {
exit(1);
}
if (!pushd(destdir)) {
- char *cmd = calloc(strlen(test->script_setup) + STASIS_BUFSIZ, sizeof(*cmd));
+ const size_t cmd_len = strlen(test->script_setup) + STASIS_BUFSIZ;
+ char *cmd = calloc(cmd_len, sizeof(*cmd));
if (!cmd) {
SYSERROR("Unable to allocate test script_setup buffer: %s", strerror(errno));
exit(1);
@@ -181,20 +187,25 @@ void delivery_tests_run(struct Delivery *ctx) {
}
struct MultiProcessingTask *task = NULL;
- char runner_cmd[0xFFFF] = {0};
- sprintf(runner_cmd, runner_cmd_fmt, cmd);
+ char *runner_cmd = NULL;
+ if (asprintf(&runner_cmd, runner_cmd_fmt, cmd) < 0) {
+ SYSERROR("Unable to allocate memory for runner command: %s", strerror(errno));
+ exit(1);
+ }
task = mp_pool_task(pool[SETUP], test->name, destdir, runner_cmd);
if (!task) {
SYSERROR("Failed to add task %s to setup pool: %s", test->name, runner_cmd);
popd();
if (!globals.continue_on_error) {
+ guard_free(runner_cmd);
tpl_free();
delivery_free(ctx);
globals_free();
}
exit(1);
}
+ guard_free(runner_cmd);
guard_free(cmd);
popd();
} else {