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 <noreply@anthropic.com>
This commit is contained in:
shivanayak
2026-03-09 23:44:32 +05:30
committed by GitHub
parent a47c923b05
commit ff4467a1a4
3 changed files with 9 additions and 3 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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