From 706fb34851be3116e28d6abd2c879f984c3d8c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 10 Jul 2019 10:22:48 +0200 Subject: [PATCH 1/2] shared/dm-util: use strncpy_exact() to silence gcc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With gcc-9.1.1-2.fc31.x86_64 and -Doptimization=2: ../src/shared/dm-util.c: In function ‘dm_deferred_remove’: ../src/shared/dm-util.c:35:9: warning: ‘strncpy’ specified bound 128 equals destination size [-Wstringop-truncation] 35 | strncpy(dm.name, name, sizeof(dm.name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc is plain wrong here, because we checked strlen(name) a few lines above, so there can be no truncation and even the terminator always fits. But let's avoid the warning. --- src/shared/dm-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/dm-util.c b/src/shared/dm-util.c index a17b85b64a..f73bf93520 100644 --- a/src/shared/dm-util.c +++ b/src/shared/dm-util.c @@ -5,6 +5,7 @@ #include "dm-util.h" #include "fd-util.h" +#include "string-util.h" int dm_deferred_remove(const char *name) { @@ -25,14 +26,14 @@ int dm_deferred_remove(const char *name) { /* Unfortunately, libcryptsetup doesn't provide a proper API for this, hence call the ioctl() * directly. */ - if (strlen(name) > sizeof(dm.name)-1) + if (strlen(name) >= sizeof(dm.name)) return -ENODEV; /* A device with a name longer than this cannot possibly exist */ fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC); if (fd < 0) return -errno; - strncpy(dm.name, name, sizeof(dm.name)); + strncpy_exact(dm.name, name, sizeof(dm.name)); if (ioctl(fd, DM_DEV_REMOVE, &dm)) return -errno; From 573e9a3310ec99c34cee8a45a860ae353ac5994c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 10 Jul 2019 10:30:12 +0200 Subject: [PATCH 2/2] networkd: silence bogus gcc warning about %s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12931. In file included from ../src/basic/macro.h:558, from ../src/basic/alloc-util.h:9, from ../src/network/networkd-link.c:7: ../src/network/networkd-link.c: In function ‘link_sysctl_ipv6_enabled’: ../src/basic/log.h:107:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 107 | log_internal_realm(LOG_REALM_PLUS_LEVEL(LOG_REALM, (level)), __VA_ARGS__) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../src/shared/log-link.h:21:25: note: in expansion of macro ‘log_internal’ 21 | log_internal(level, error, _FILE_, __LINE__, __func__, ##__VA_ARGS__); \ | ^~~~~~~~~~~~ ../src/shared/log-link.h:33:50: note: in expansion of macro ‘log_link_full’ 33 | #define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__) | ^~~~~~~~~~~~~ ../src/network/networkd-link.c:83:24: note: in expansion of macro ‘log_link_warning_errno’ 83 | return log_link_warning_errno(link, r, | ^~~~~~~~~~~~~~~~~~~~~~ ../src/network/networkd-link.c:84:77: note: format string is defined here 84 | "Failed to read net.ipv6.conf.%s.disable_ipv6 sysctl property: %m", | ^~ cc1: some warnings being treated as errors --- src/network/networkd-link.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 5f91d66dc0..f45d881cf8 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -78,11 +78,12 @@ int link_sysctl_ipv6_enabled(Link *link) { if (link->sysctl_ipv6_enabled >= 0) return link->sysctl_ipv6_enabled; - r = sysctl_read_ip_property(AF_INET6, link->ifname, "disable_ipv6", &value); + const char *ifname = link->ifname; /* work around bogus gcc warning */ + r = sysctl_read_ip_property(AF_INET6, ifname, "disable_ipv6", &value); if (r < 0) return log_link_warning_errno(link, r, "Failed to read net.ipv6.conf.%s.disable_ipv6 sysctl property: %m", - link->ifname); + ifname); link->sysctl_ipv6_enabled = value[0] == '0'; return link->sysctl_ipv6_enabled;