From 347677c3330ece8496b9cd242fd7e4292c2260ae Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Apr 2026 15:55:21 -0400 Subject: NUL terminate after copy --- src/lib/delivery/delivery_init.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/lib/delivery/delivery_init.c') diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index ff877f0..a163f01 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -178,22 +178,30 @@ int delivery_init_platform(struct Delivery *ctx) { } else { strncpy(archsuffix, ctx->system.arch, sizeof(archsuffix) - 1); } + archsuffix[sizeof(archsuffix) - 1] = '\0'; SYSDEBUG("%s", "Setting platform"); strncpy(ctx->system.platform[DELIVERY_PLATFORM], uts.sysname, DELIVERY_PLATFORM_MAXLEN - 1); if (!strcmp(ctx->system.platform[DELIVERY_PLATFORM], "Darwin")) { snprintf(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], DELIVERY_PLATFORM_MAXLEN, "osx-%s", archsuffix); strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "MacOSX", DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "macos", DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; } else if (!strcmp(ctx->system.platform[DELIVERY_PLATFORM], "Linux")) { snprintf(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], DELIVERY_PLATFORM_MAXLEN, "linux-%s", archsuffix); strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], "Linux", DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], "linux", DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; } else { // Not explicitly supported systems strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_CONDA_SUBDIR][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; strncpy(ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_CONDA_INSTALLER][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; strncpy(ctx->system.platform[DELIVERY_PLATFORM_RELEASE], ctx->system.platform[DELIVERY_PLATFORM], DELIVERY_PLATFORM_MAXLEN - 1); + ctx->system.platform[DELIVERY_PLATFORM_RELEASE][DELIVERY_PLATFORM_MAXLEN - 1] = '\0'; tolower_s(ctx->system.platform[DELIVERY_PLATFORM_RELEASE]); } -- cgit From 7b7d84b3bea179d607fae2db5de7613adef1a6fd Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 25 Apr 2026 10:15:35 -0400 Subject: delivery_init_tmpdir: reverse error condition to clean up goto logic --- src/lib/delivery/delivery_init.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/lib/delivery/delivery_init.c') diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index a163f01..9a2f6c3 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -12,7 +12,7 @@ int has_mount_flags(const char *mount_point, const unsigned long flags) { int delivery_init_tmpdir(struct Delivery *ctx) { char *tmpdir = NULL; char *x = NULL; - int unusable = 0; + int unusable = 1; errno = 0; x = getenv("TMPDIR"); @@ -25,7 +25,8 @@ int delivery_init_tmpdir(struct Delivery *ctx) { if (!tmpdir) { // memory error - return -1; + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; } // If the directory doesn't exist, create it @@ -61,15 +62,25 @@ int delivery_init_tmpdir(struct Delivery *ctx) { if (!globals.tmpdir) { globals.tmpdir = strdup(tmpdir); + if (!globals.tmpdir) { + SYSERROR("%s", "unable to allocate globals.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } if (!ctx->storage.tmpdir) { ctx->storage.tmpdir = strdup(globals.tmpdir); + if (!ctx->storage.tmpdir) { + SYSERROR("%s", "unable to allocate globals.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } - return unusable; + unusable = 0; l_delivery_init_tmpdir_fatal: - unusable = 1; + if (unusable) { + guard_free(tmpdir); + } return unusable; } -- cgit From 8f209a9ab8dfca02ce5c53f50d87919b7202e3f1 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 25 Apr 2026 16:35:28 -0400 Subject: Set starting TMPDIR to /tmp/stasis * Easier to remove leftover files, if any * Now uses setenv() to have better control over external programs * Removes the hack to initialize TMPDIR early --- src/lib/delivery/delivery_init.c | 44 +++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'src/lib/delivery/delivery_init.c') diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index 9a2f6c3..17f3899 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -11,24 +11,43 @@ int has_mount_flags(const char *mount_point, const unsigned long flags) { int delivery_init_tmpdir(struct Delivery *ctx) { char *tmpdir = NULL; - char *x = NULL; int unusable = 1; errno = 0; - x = getenv("TMPDIR"); + int need_setenv = 0; + const char *x = getenv("TMPDIR"); if (x) { guard_free(ctx->storage.tmpdir); tmpdir = strdup(x); + if (!tmpdir) { + // memory error + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } else { - tmpdir = ctx->storage.tmpdir; + tmpdir = strdup("/tmp/stasis"); + if (!tmpdir) { + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } + need_setenv = 1; } - if (!tmpdir) { - // memory error - SYSERROR("%s", "unable to allocate tmpdir"); - goto l_delivery_init_tmpdir_fatal; + if (!ctx->storage.tmpdir) { + ctx->storage.tmpdir = strdup(tmpdir); + if (!ctx->storage.tmpdir) { + SYSERROR("%s", "unable to allocate ctx->storage.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } + } else { + // we already have a temp directory to use + guard_free(tmpdir); + tmpdir = strdup(ctx->storage.tmpdir); + if (!tmpdir) { + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } - // If the directory doesn't exist, create it if (access(tmpdir, F_OK) < 0) { if (mkdirs(tmpdir, 0755) < 0) { @@ -60,7 +79,7 @@ int delivery_init_tmpdir(struct Delivery *ctx) { goto l_delivery_init_tmpdir_fatal; } - if (!globals.tmpdir) { + if (!globals.tmpdir || strcmp(globals.tmpdir, ctx->storage.tmpdir) != 0) { globals.tmpdir = strdup(tmpdir); if (!globals.tmpdir) { SYSERROR("%s", "unable to allocate globals.tmpdir"); @@ -76,11 +95,12 @@ int delivery_init_tmpdir(struct Delivery *ctx) { } } unusable = 0; + if (need_setenv) { + setenv("TMPDIR", ctx->storage.tmpdir, 1); + } l_delivery_init_tmpdir_fatal: - if (unusable) { - guard_free(tmpdir); - } + guard_free(tmpdir); return unusable; } -- cgit From 6a9f076f69d233f75ec78e74b77fefa5e9ed92db Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Apr 2026 18:12:21 -0400 Subject: disable setting TMPDIR --- src/lib/delivery/delivery_init.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/lib/delivery/delivery_init.c') diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index 17f3899..ec05a0f 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -14,7 +14,7 @@ int delivery_init_tmpdir(struct Delivery *ctx) { int unusable = 1; errno = 0; - int need_setenv = 0; + //int need_setenv = 0; const char *x = getenv("TMPDIR"); if (x) { guard_free(ctx->storage.tmpdir); @@ -30,7 +30,7 @@ int delivery_init_tmpdir(struct Delivery *ctx) { SYSERROR("%s", "unable to allocate tmpdir"); goto l_delivery_init_tmpdir_fatal; } - need_setenv = 1; + //need_setenv = 1; } if (!ctx->storage.tmpdir) { @@ -95,9 +95,10 @@ int delivery_init_tmpdir(struct Delivery *ctx) { } } unusable = 0; - if (need_setenv) { - setenv("TMPDIR", ctx->storage.tmpdir, 1); - } + // TODO: Figure out why this breaks EVERYTHING + //if (need_setenv) { + // setenv("TMPDIR", ctx->storage.tmpdir, 1); + //} l_delivery_init_tmpdir_fatal: guard_free(tmpdir); -- cgit