From 8daa61dae354ea3c5138222e2de2ab15e23f6d3a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 23 Oct 2017 16:59:10 +0200 Subject: [PATCH] platform: fix return value for nm_platform_sysctl_set() When comparing an unsigned and a signed integer, the signed integer is promoted to unsigned, resulting in a very large number. See the checks "nwrote < len - 1", where nwrote might be -1 to indicate failure. The condition would not be TRUE due to promoting -1 to the max int value. Hence, sysctl_set() was rather wrong. --- src/platform/nm-linux-platform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 440d2760c..d304bdfbf 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2934,7 +2934,7 @@ sysctl_set (NMPlatform *platform, const char *pathid, int dirfd, const char *pat nm_auto_pop_netns NMPNetns *netns = NULL; int fd, tries; gssize nwrote; - gsize len; + gssize len; char *actual; gs_free char *actual_free = NULL; int errsv; @@ -2989,6 +2989,7 @@ sysctl_set (NMPlatform *platform, const char *pathid, int dirfd, const char *pat * about to write. */ len = strlen (value) + 1; + nm_assert (len > 0); if (len > 512) actual = actual_free = g_malloc (len + 1); else