From 0de2a305fc2187f62b3df36d7541e7f4fa254f61 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 20 Sep 2024 08:45:20 -0400 Subject: Fix string op warnings * Fix unused-result warnings --- src/utils.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index c0b3733..63c0cb7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -34,7 +34,7 @@ int popd() { int rmtree(char *_path) { int status = 0; char path[PATH_MAX] = {0}; - strncpy(path, _path, sizeof(path)); + strncpy(path, _path, sizeof(path) - 1); DIR *dir; struct dirent *d_entity; @@ -122,10 +122,10 @@ char *expandpath(const char *_path) { } // Construct the new path - strncat(result, home, PATH_MAX - 1); + strncat(result, home, sizeof(result) - strlen(home) + 1); if (sep) { - strncat(result, DIR_SEP, PATH_MAX - 1); - strncat(result, ptmp, PATH_MAX - 1); + strncat(result, DIR_SEP, sizeof(result) - strlen(home) + 1); + strncat(result, ptmp, sizeof(result) - strlen(home) + 1); } return strdup(result); @@ -444,7 +444,10 @@ void msg(unsigned type, char *fmt, ...) { void debug_shell() { msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "ENTERING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET); - system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'"); + if (system("/bin/bash -c 'PS1=\"(STASIS DEBUG) \\W $ \" bash --norc --noprofile'") < 0) { + SYSERROR("unable to spawn debug shell: %s", strerror(errno)); + exit(errno); + } msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "EXITING STASIS DEBUG SHELL\n" STASIS_COLOR_RESET); exit(255); } -- cgit From 8621754d1126b0047a4e5817b85dcf0e8749e721 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 27 Sep 2024 10:05:14 -0400 Subject: Squelch git's detached HEAD message --- src/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 63c0cb7..3a98f28 100644 --- a/src/utils.c +++ b/src/utils.c @@ -315,7 +315,7 @@ int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) { } static char command[PATH_MAX]; - sprintf(command, "%s clone --recursive %s", program, url); + sprintf(command, "%s clone -c advice.detachedHead=false --recursive %s", program, url); if (destdir && access(destdir, F_OK) < 0) { sprintf(command + strlen(command), " %s", destdir); result = shell(proc, command); -- cgit From a84b874a027fd8007efc10e0602396c4b5da170c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 27 Sep 2024 16:29:03 -0400 Subject: Fix leak * When strdup fails and the temporary file handle is open, close the handle and die. * reported by @kmacdonald-stsci --- src/utils.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 3a98f28..e037088 100644 --- a/src/utils.c +++ b/src/utils.c @@ -468,12 +468,23 @@ char *xmkstemp(FILE **fp, const char *mode) { fd = mkstemp(t_name); *fp = fdopen(fd, mode); if (!*fp) { + // unable to open, die if (fd > 0) close(fd); *fp = NULL; return NULL; } + char *path = strdup(t_name); + if (!path) { + // strdup failed, die + if (*fp) { + // close the file handle + fclose(*fp); + *fp = NULL; + } + // fall through. path is NULL. + } return path; } -- cgit