From 50fd596efcd0f556104a05ba2c6a35400ae989eb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 May 2021 19:38:34 +0900 Subject: [PATCH 1/4] path-util: add missing varargs cleanup Fixes CID#1453293. --- src/basic/path-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 2742a27672..82f3709042 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -577,12 +577,13 @@ char* path_extend_internal(char **x, ...) { continue; add = 1 + strlen(p); - if (sz > SIZE_MAX - add) /* overflow check */ + if (sz > SIZE_MAX - add) { /* overflow check */ + va_end(ap); return NULL; + } sz += add; } - va_end(ap); nx = realloc(x ? *x : NULL, GREEDY_ALLOC_ROUND_UP(sz+1)); From a04842dfb2e1d20e73b342de824bda1efd7a9be0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 May 2021 19:41:03 +0900 Subject: [PATCH 2/4] network,sd-hwdb: voidify fchmod() Fixes CID#1453294. --- src/libsystemd/sd-hwdb/hwdb-util.c | 2 +- src/network/networkd-lldp-rx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index fd45ff0f54..8964a40e38 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -377,7 +377,7 @@ static int trie_store(struct trie *trie, const char *filename, bool compat) { r = fopen_temporary(filename, &t.f, &filename_tmp); if (r < 0) return r; - fchmod(fileno(t.f), 0444); + (void) fchmod(fileno(t.f), 0444); /* write nodes */ if (fseeko(t.f, sizeof(struct trie_header_f), SEEK_SET) < 0) diff --git a/src/network/networkd-lldp-rx.c b/src/network/networkd-lldp-rx.c index 5b1b90cdd3..d781f443d6 100644 --- a/src/network/networkd-lldp-rx.c +++ b/src/network/networkd-lldp-rx.c @@ -163,7 +163,7 @@ int link_lldp_save(Link *link) { if (r < 0) goto finish; - fchmod(fileno(f), 0644); + (void) fchmod(fileno(f), 0644); for (i = 0; i < n; i++) { const void *p; From 7f1238bd04000f3333e8e2fcb82c9c6e18ee3ffc Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 May 2021 19:48:33 +0900 Subject: [PATCH 3/4] basic/unit-file: fix use-after-free This fixes a bug introduced by e8630e695232bdfcd16b55f3faafb4329c961104. Fixes CID#1453292. --- src/basic/unit-file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index fab63b6dce..f20ae4dbe5 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -303,11 +303,11 @@ int unit_file_build_name_map( return log_oom(); if (paths) { - r = set_consume(paths, filename); + r = set_put(paths, filename); if (r < 0) return log_oom(); - /* We will still use filename below. This is safe because we know the set - * holds a reference. */ + if (r == 0) + _filename_free = filename; /* Make sure we free the filename. */ } else _filename_free = filename; /* Make sure we free the filename. */ From 48008c1cbf932dbdbe25fa88e9c05bf162bcdae8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 May 2021 19:52:12 +0900 Subject: [PATCH 4/4] tree-wide: fix typo --- man/sd_id128_get_machine.xml | 2 +- src/core/unit.c | 4 ++-- src/libsystemd/sd-device/sd-device.c | 2 +- src/test/test-alloc-util.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/sd_id128_get_machine.xml b/man/sd_id128_get_machine.xml index 7fa9860898..caf4caa300 100644 --- a/man/sd_id128_get_machine.xml +++ b/man/sd_id128_get_machine.xml @@ -106,7 +106,7 @@ but might not on older. It is possible to convert the machine ID into a UUID v4-compatible one. For more information, see machine-id5. It is - hence guaranteed that thes functions will never return the ID consisting of all zero or all one bits + hence guaranteed that these functions will never return the ID consisting of all zero or all one bits (SD_ID128_NULL, SD_ID128_ALLF) — with the possible exception of sd_id128_get_machine(), as mentioned. diff --git a/src/core/unit.c b/src/core/unit.c index e48e7602c2..dbdf7d9b37 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2708,7 +2708,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag } /* And now, add the unit or depending units to various queues that will act on the new situation if - * needed. These queues generally check for continous state changes rather than events (like most of + * needed. These queues generally check for continuous state changes rather than events (like most of * the state propagation above), and do work deferred instead of instantly, since they typically * don't want to run during reloading, and usually involve checking combined state of multiple units * at once. */ @@ -5831,7 +5831,7 @@ int unit_get_dependency_array(const Unit *u, UnitDependencyAtom atom, Unit ***re /* Gets a list of units matching a specific atom as array. This is useful when iterating through * dependencies while modifying them: the array is an "atomic snapshot" of sorts, that can be read - * while the dependency table is continously updated. */ + * while the dependency table is continuously updated. */ UNIT_FOREACH_DEPENDENCY(other, u, atom) { if (!GREEDY_REALLOC(array, n + 1)) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index de0798f4d8..eff852c335 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -2141,7 +2141,7 @@ _public_ int sd_device_trigger_with_uuid( assert_return(device, -EINVAL); - /* If noone wants to know the UUID, use the simple interface from pre-4.13 times */ + /* If no one wants to know the UUID, use the simple interface from pre-4.13 times */ if (!ret_uuid) return sd_device_trigger(device, action); diff --git a/src/test/test-alloc-util.c b/src/test/test-alloc-util.c index 2baae0cb9b..fb69009d97 100644 --- a/src/test/test-alloc-util.c +++ b/src/test/test-alloc-util.c @@ -175,7 +175,7 @@ static void test_malloc_size_safe(void) { assert_se(malloc_usable_size(NULL) == 0); /* as per man page, this is safe and defined */ assert_se(__builtin_object_size(NULL, 0) == SIZE_MAX); /* as per docs SIZE_MAX is returned for pointers where the size isn't known */ - /* Then, let's try these macros once with contant size values, so that __builtin_object_size() + /* Then, let's try these macros once with constant size values, so that __builtin_object_size() * definitely can work (as long as -O2 is used when compiling) */ assert_se(f = new(uint32_t, n)); TEST_SIZES(f, n);