1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

coredumpctl: check return value

retrieve() allocates memory, so it may fail.
Coverity CID#1402338.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-07-17 10:02:13 +02:00
parent eba048bb6e
commit 2d0a880fea

View File

@ -738,9 +738,22 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
/* Look for a coredump on disk first. */
r = sd_journal_get_data(j, "COREDUMP_FILENAME", (const void**) &data, &len);
if (r == 0)
retrieve(data, len, "COREDUMP_FILENAME", &filename);
else {
if (r == 0) {
r = retrieve(data, len, "COREDUMP_FILENAME", &filename);
if (r < 0)
return r;
assert(r > 0);
if (access(filename, R_OK) < 0)
return log_error_errno(errno, "File \"%s\" is not readable: %m", filename);
if (path && !endswith(filename, ".xz") && !endswith(filename, ".lz4")) {
*path = TAKE_PTR(filename);
return 0;
}
} else {
if (r != -ENOENT)
return log_error_errno(r, "Failed to retrieve COREDUMP_FILENAME field: %m");
/* Check that we can have a COREDUMP field. We still haven't set a high
@ -754,17 +767,6 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp)
return log_error_errno(r, "Failed to retrieve COREDUMP field: %m");
}
if (filename) {
if (access(filename, R_OK) < 0)
return log_error_errno(errno, "File \"%s\" is not readable: %m", filename);
if (path && !endswith(filename, ".xz") && !endswith(filename, ".lz4")) {
*path = TAKE_PTR(filename);
return 0;
}
}
if (path) {
const char *vt;