summaryrefslogtreecommitdiff
path: root/src/journal/journalctl.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2014-07-25 15:38:31 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-26 15:08:41 -0400
commit7de80bfe2e61d5818601ccfddbadad3b7703ed70 (patch)
treeb8b90c03198f2f2125d13e175b2223e6239894f0 /src/journal/journalctl.c
parent6d314eca15f6cbda38d82774b210f784d3d4f52a (diff)
Always check asprintf return code
There is a small number of the places in sources where we don't check asprintf() return code and assume that after error the function returns NULL pointer via the first argument. That's wrong, after error the content of pointer is undefined.
Diffstat (limited to 'src/journal/journalctl.c')
-rw-r--r--src/journal/journalctl.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 7aedbf0c57..5a59a3ac83 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -746,11 +746,17 @@ static int add_matches(sd_journal *j, char **args) {
}
} else
t = strappend("_EXE=", path);
- } else if (S_ISCHR(st.st_mode))
- asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev));
- else if (S_ISBLK(st.st_mode))
- asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev));
- else {
+ } else if (S_ISCHR(st.st_mode)) {
+ if (asprintf(&t, "_KERNEL_DEVICE=c%u:%u",
+ major(st.st_rdev),
+ minor(st.st_rdev)) < 0)
+ return -ENOMEM;
+ } else if (S_ISBLK(st.st_mode)) {
+ if (asprintf(&t, "_KERNEL_DEVICE=b%u:%u",
+ major(st.st_rdev),
+ minor(st.st_rdev)) < 0)
+ return -ENOMEM;
+ } else {
log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
return -EINVAL;
}