From ff4467a1a48e8c9854b4ab6da5ce16a15741f0db Mon Sep 17 00:00:00 2001 From: shivanayak Date: Mon, 9 Mar 2026 23:44:32 +0530 Subject: [PATCH] daemon: fix low severity bugs in debug, file, and blkid (#315) - debug.c: fix memory leak of out buffer on opendir failure in debug_fds. After fclose on open_memstream, the out buffer is allocated and must be freed. - file.c: add missing reply_with_perror on strdup failure in do_zfile, so callers get a proper error message instead of silent NULL return. - blkid.c: fix wrong error variable used at command_failed label in test_blkid_p_i_opt. The second commandr stores its error in err2, but goto command_failed would report err from the first command. Inline the error reporting with the correct variable. Co-authored-by: Claude --- daemon/blkid.c | 6 ++++-- daemon/debug.c | 1 + daemon/file.c | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/daemon/blkid.c b/daemon/blkid.c index fea322f5e..5751a4d89 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -112,8 +112,10 @@ test_blkid_p_i_opt (void) } r = commandr (NULL, &err2, "blkid", "-i", NULL); - if (r == -1) - goto command_failed; + if (r == -1) { + reply_with_error ("could not run 'blkid' command: %s", err2); + return -1; + } if (strstr (err2, "invalid option --")) { return 0; diff --git a/daemon/debug.c b/daemon/debug.c index 484318f7a..da504e839 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -164,6 +164,7 @@ debug_fds (const char *subcmd, size_t argc, char *const *const argv) if (!dir) { reply_with_perror ("opendir: /proc/self/fd"); fclose (fp); + free (out); return NULL; } diff --git a/daemon/file.c b/daemon/file.c index 9464d3bd0..16f08f500 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -501,7 +501,10 @@ do_zfile (const char *method, const char *path) if (len > 0 && line[len-1] == '\n') line[len-1] = '\0'; - return strdup (line); + char *ret = strdup (line); + if (ret == NULL) + reply_with_perror ("strdup"); + return ret; } int64_t