]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: fix signed/unsigned confusion
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 May 2020 05:40:31 +0000 (07:40 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 May 2020 06:13:11 +0000 (08:13 +0200)
sd_dhcp_lease_get_servers() returns int, which would never be negative when
cast to size_t, so we condition check was wrong.

CID#1425417.

src/network/networkd-dhcp-server.c

index 2e9cef590fffb7e81c058bdb7f0b140360603397..87659909a02883ce1ffa11e6d8502fff9fc2ad50 100644 (file)
@@ -160,12 +160,12 @@ static int link_push_uplink_to_dhcp_server(
         if (lease_condition && link->dhcp_lease) {
                 const struct in_addr *da;
 
-                size_t n = sd_dhcp_lease_get_servers(link->dhcp_lease, what, &da);
+                int n = sd_dhcp_lease_get_servers(link->dhcp_lease, what, &da);
                 if (n > 0) {
                         if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n))
                                 return log_oom();
 
-                        for (unsigned i = 0; i < n; i++)
+                        for (int i = 0; i < n; i++)
                                 if (in4_addr_is_non_local(&da[i]))
                                         addresses[n_addresses++] = da[i];
                 }