From 48440643f7a994ad8620daaafed4d914f723440d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:26:02 +0200 Subject: [PATCH 01/12] journal: voidify fd_nonblock() CID #1396098 CID #1396096 CID #1396091 CID #1396086 --- src/journal/journald-audit.c | 2 +- src/journal/journald-native.c | 2 +- src/journal/journald-stream.c | 2 +- src/journal/journald-syslog.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 87726684af..68d889b5fb 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -526,7 +526,7 @@ int server_open_audit(Server *s) { return 0; } } else - fd_nonblock(s->audit_fd, 1); + (void) fd_nonblock(s->audit_fd, true); r = setsockopt(s->audit_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); if (r < 0) diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index b2f6e11dba..44610a4b3b 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -461,7 +461,7 @@ int server_open_native_socket(Server*s) { (void) chmod(sa.un.sun_path, 0666); } else - fd_nonblock(s->native_fd, 1); + (void) fd_nonblock(s->native_fd, true); r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); if (r < 0) diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index dbf3503a82..267e63f4a2 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -804,7 +804,7 @@ int server_open_stdout_socket(Server *s) { if (listen(s->stdout_fd, SOMAXCONN) < 0) return log_error_errno(errno, "listen(%s) failed: %m", sa.un.sun_path); } else - fd_nonblock(s->stdout_fd, 1); + (void) fd_nonblock(s->stdout_fd, true); r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s); if (r < 0) diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 72b73c2c0f..46cc110f1c 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -465,7 +465,7 @@ int server_open_syslog_socket(Server *s) { (void) chmod(sa.un.sun_path, 0666); } else - fd_nonblock(s->syslog_fd, 1); + (void) fd_nonblock(s->syslog_fd, true); r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); if (r < 0) From b9839ac9d96a4f36beb7d3420d560aed3aa4fb89 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:31:30 +0200 Subject: [PATCH 02/12] cgroup: make sure whitelist_device() always returns a valid return value CID 1396094 --- src/core/cgroup.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 9f5e67ba22..ff5f1d5171 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -418,8 +418,9 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node if (!prog) return 0; - cgroup_bpf_whitelist_device(prog, S_ISCHR(st.st_mode) ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK, - major(st.st_rdev), minor(st.st_rdev), acc); + return cgroup_bpf_whitelist_device(prog, S_ISCHR(st.st_mode) ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK, + major(st.st_rdev), minor(st.st_rdev), acc); + } else { char buf[2+DECIMAL_STR_MAX(dev_t)*2+2+4]; @@ -431,11 +432,11 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node r = cg_set_attribute("devices", path, "devices.allow", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING, - r, "Failed to set devices.allow on %s: %m", path); - } + return log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING, + r, "Failed to set devices.allow on %s: %m", path); - return r; + return 0; + } } static int whitelist_major(BPFProgram *prog, const char *path, const char *name, char type, const char *acc) { From 913c898ca01f4ad90a38684505f88b7d0e6724fd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:32:22 +0200 Subject: [PATCH 03/12] cgroup: voidify a few things --- src/core/cgroup.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index ff5f1d5171..c89f57a67f 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -500,9 +500,9 @@ static int whitelist_major(BPFProgram *prog, const char *path, const char *name, if (!prog) continue; - cgroup_bpf_whitelist_major(prog, - type == 'c' ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK, - maj, acc); + (void) cgroup_bpf_whitelist_major(prog, + type == 'c' ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK, + maj, acc); } else { char buf[2+DECIMAL_STR_MAX(unsigned)+3+4]; @@ -1080,10 +1080,10 @@ static void cgroup_context_apply( const char *x, *y; NULSTR_FOREACH_PAIR(x, y, auto_devices) - whitelist_device(prog, path, x, y); + (void) whitelist_device(prog, path, x, y); /* PTS (/dev/pts) devices may not be duplicated, but accessed */ - whitelist_major(prog, path, "pts", 'c', "rw"); + (void) whitelist_major(prog, path, "pts", 'c', "rw"); } LIST_FOREACH(device_allow, a, c->device_allow) { @@ -1103,11 +1103,11 @@ static void cgroup_context_apply( acc[k++] = 0; if (path_startswith(a->path, "/dev/")) - whitelist_device(prog, path, a->path, acc); + (void) whitelist_device(prog, path, a->path, acc); else if ((val = startswith(a->path, "block-"))) - whitelist_major(prog, path, val, 'b', acc); + (void) whitelist_major(prog, path, val, 'b', acc); else if ((val = startswith(a->path, "char-"))) - whitelist_major(prog, path, val, 'c', acc); + (void) whitelist_major(prog, path, val, 'c', acc); else log_unit_debug(u, "Ignoring device %s while writing cgroup attribute.", a->path); } From fcadf032c00f94a323fe0d15e45dd42b9765d979 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:38:40 +0200 Subject: [PATCH 04/12] json: fix memleak on OOM CID 1396083 --- src/basic/json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/basic/json.c b/src/basic/json.c index df3141fb2a..426ed0328e 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -2560,7 +2560,7 @@ int json_buildv(JsonVariant **ret, va_list ap) { }; for (;;) { - JsonVariant *add = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *add = NULL; JsonStack *current; int command; @@ -2899,7 +2899,7 @@ int json_buildv(JsonVariant **ret, va_list ap) { goto finish; } - current->elements[current->n_elements++] = add; + current->elements[current->n_elements++] = TAKE_PTR(add); } } From 76f713dfa47f803ef843ea2ae86ab2db2eea37d6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:47:28 +0200 Subject: [PATCH 05/12] sd-ndisc: voidify sd_ndisc_stop() call CID 1395839 --- src/libsystemd-network/sd-ndisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index 126a2929a9..6f0e2ca0df 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -301,7 +301,7 @@ static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) { return 0; fail: - sd_ndisc_stop(nd); + (void) sd_ndisc_stop(nd); return 0; } From 165ad41b7fb97fb61e5436896dbaeb1b3e62f2e2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:49:18 +0200 Subject: [PATCH 06/12] sd-ndisc: change return value of ndisc_reset() to void We never generate anything other than 0 anyway, and we never check it, hence let's just simplify things. --- src/libsystemd-network/sd-ndisc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index 6f0e2ca0df..d679fc8222 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -100,7 +100,7 @@ _public_ sd_event *sd_ndisc_get_event(sd_ndisc *nd) { return nd->event; } -static int ndisc_reset(sd_ndisc *nd) { +static void ndisc_reset(sd_ndisc *nd) { assert(nd); nd->timeout_event_source = sd_event_source_unref(nd->timeout_event_source); @@ -108,8 +108,6 @@ static int ndisc_reset(sd_ndisc *nd) { nd->retransmit_time = 0; nd->recv_event_source = sd_event_source_unref(nd->recv_event_source); nd->fd = safe_close(nd->fd); - - return 0; } static sd_ndisc *ndisc_free(sd_ndisc *nd) { From 9db296fdddee5645567ad0c0edff37481361b91b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:50:46 +0200 Subject: [PATCH 07/12] efivars: add missing OOM check CID #1395833 --- src/shared/efivars.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shared/efivars.c b/src/shared/efivars.c index da70e68c81..7a9754096c 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -455,6 +455,9 @@ int efi_get_boot_option( /* Sub-Type 4 – File Path */ if (dpath->sub_type == MEDIA_FILEPATH_DP && !p && path) { p = utf16_to_utf8(dpath->path, dpath->length-4); + if (!p) + return -ENOMEM; + efi_tilt_backslashes(p); continue; } From babdf0d3153838187d0760fa676a7ce4e5badd5e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:52:11 +0200 Subject: [PATCH 08/12] udevadm: assert_se() around sigprocmask() CID #1395708 --- src/udev/udevadm-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 89d51c7775..d2868d114c 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -105,7 +105,7 @@ int test_main(int argc, char *argv[], void *userdata) { "some values may be different, or not available at a simulation run.\n" "\n"); - sigprocmask(SIG_SETMASK, NULL, &sigmask_orig); + assert_se(sigprocmask(SIG_SETMASK, NULL, &sigmask_orig) >= 0); udev_builtin_init(); From db2d75dfbb9dc96b88a0d6569cf4660995499133 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:53:17 +0200 Subject: [PATCH 09/12] machinectl: voidify calls to sd_event_add_signal() CID 1394445 --- src/machine/machinectl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index f28174bf8b..2f21f99957 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1325,8 +1325,8 @@ static int process_forward(sd_event *event, PTYForward **forward, int master, PT log_info("Connected to machine %s. Press ^] three times within 1s to exit session.", name); } - sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); + (void) sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); + (void) sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); r = pty_forward_new(event, master, flags, forward); if (r < 0) @@ -1983,8 +1983,8 @@ static int transfer_image_common(sd_bus *bus, sd_bus_message *m) { if (!arg_quiet) log_info("Enqueued transfer job %u. Press C-c to continue download in background.", id); - sd_event_add_signal(event, NULL, SIGINT, transfer_signal_handler, UINT32_TO_PTR(id)); - sd_event_add_signal(event, NULL, SIGTERM, transfer_signal_handler, UINT32_TO_PTR(id)); + (void) sd_event_add_signal(event, NULL, SIGINT, transfer_signal_handler, UINT32_TO_PTR(id)); + (void) sd_event_add_signal(event, NULL, SIGTERM, transfer_signal_handler, UINT32_TO_PTR(id)); r = sd_event_loop(event); if (r < 0) From 0b2c35b812762ae1017a022900d6876d9708f8c6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:54:37 +0200 Subject: [PATCH 10/12] wait-online: more voidifyin of sd_event_add_signal() CID 1394444 --- src/network/wait-online/manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c index 25072cc5b1..c054c2a96d 100644 --- a/src/network/wait-online/manager.c +++ b/src/network/wait-online/manager.c @@ -263,8 +263,8 @@ int manager_new(Manager **ret, char **interfaces, char **ignore, usec_t timeout) if (r < 0) return r; - sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL); - sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); + (void) sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL); + (void) sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); if (timeout > 0) { usec_t usec; From c504106c356cb6a5d4bb9416ca1c35c5b495f736 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 18:59:23 +0200 Subject: [PATCH 11/12] journal-upload: check for overflow CID 1394386 --- src/journal-remote/journal-upload.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 157ed413b1..621fd620ee 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -280,8 +280,7 @@ int start_upload(Uploader *u, static size_t fd_input_callback(void *buf, size_t size, size_t nmemb, void *userp) { Uploader *u = userp; - - ssize_t r; + ssize_t n; assert(u); assert(nmemb < SSIZE_MAX / size); @@ -289,21 +288,22 @@ static size_t fd_input_callback(void *buf, size_t size, size_t nmemb, void *user if (u->input < 0) return 0; - r = read(u->input, buf, size * nmemb); - log_debug("%s: allowed %zu, read %zd", __func__, size*nmemb, r); + assert(!size_multiply_overflow(size, nmemb)); - if (r > 0) - return r; + n = read(u->input, buf, size * nmemb); + log_debug("%s: allowed %zu, read %zd", __func__, size*nmemb, n); + if (n > 0) + return n; u->uploading = false; - if (r == 0) { - log_debug("Reached EOF"); - close_fd_input(u); - return 0; - } else { + if (n < 0) { log_error_errno(errno, "Aborting transfer after read error on input: %m."); return CURL_READFUNC_ABORT; } + + log_debug("Reached EOF"); + close_fd_input(u); + return 0; } static void close_fd_input(Uploader *u) { From ee7b9f1dfc4653cc8ce26d57cbed249d7f9cea4b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 12 Oct 2018 19:02:23 +0200 Subject: [PATCH 12/12] format-table: don't use unsigned when there's no point in it CID 1394372 --- src/basic/format-table.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/format-table.c b/src/basic/format-table.c index e30460eab6..5c99c398c2 100644 --- a/src/basic/format-table.c +++ b/src/basic/format-table.c @@ -73,11 +73,11 @@ typedef struct TableData { } TableData; static size_t TABLE_CELL_TO_INDEX(TableCell *cell) { - unsigned i; + size_t i; assert(cell); - i = PTR_TO_UINT(cell); + i = PTR_TO_SIZE(cell); assert(i > 0); return i-1; @@ -85,7 +85,7 @@ static size_t TABLE_CELL_TO_INDEX(TableCell *cell) { static TableCell* TABLE_INDEX_TO_CELL(size_t index) { assert(index != (size_t) -1); - return UINT_TO_PTR((unsigned) (index + 1)); + return SIZE_TO_PTR(index + 1); } struct Table {