summaryrefslogtreecommitdiffstats
path: root/src/coredump
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-17 10:02:13 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-17 11:35:04 +0200
commit2d0a880fea8541289929bb8af146524ceebf6d61 (patch)
treefe8f2f5c735cd346f8f45e0d5ff96296ba0dc13a /src/coredump
parentcoredumpctl: use free_and_replace in one more place (diff)
downloadsystemd-2d0a880fea8541289929bb8af146524ceebf6d61.tar.xz
systemd-2d0a880fea8541289929bb8af146524ceebf6d61.zip
coredumpctl: check return value
retrieve() allocates memory, so it may fail. Coverity CID#1402338.
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredumpctl.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c
index 2b17dc5859..292c1861dc 100644
--- a/src/coredump/coredumpctl.c
+++ b/src/coredump/coredumpctl.c
@@ -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;