]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network-internal: do not save partially parsed values
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 16 Nov 2025 04:59:56 +0000 (13:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 16 Nov 2025 05:01:28 +0000 (14:01 +0900)
src/libsystemd-network/network-internal.c

index e7c22c9b76e051f743c63e2c3a9169dff07626bf..c8aa6b63e08616ff1544844d0b204f034f811563 100644 (file)
@@ -261,8 +261,7 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, const
                 if (r == 0)
                         break;
 
-                if (!GREEDY_REALLOC(routes, size + 1))
-                        return -ENOMEM;
+                struct sd_dhcp_route route = {};
 
                 tok = word;
 
@@ -272,7 +271,7 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, const
                         continue;
                 *tok_end = '\0';
 
-                r = inet_aton(tok, &routes[size].dst_addr);
+                r = inet_aton(tok, &route.dst_addr);
                 if (r == 0)
                         continue;
 
@@ -289,15 +288,18 @@ int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, const
                 if (r < 0 || n > 32)
                         continue;
 
-                routes[size].dst_prefixlen = (uint8_t) n;
+                route.dst_prefixlen = (uint8_t) n;
                 tok = tok_end + 1;
 
                 /* get the gateway */
-                r = inet_aton(tok, &routes[size].gw_addr);
+                r = inet_aton(tok, &route.gw_addr);
                 if (r == 0)
                         continue;
 
-                size++;
+                if (!GREEDY_REALLOC(routes, size + 1))
+                        return -ENOMEM;
+
+                routes[size++] = route;
         }
 
         *ret_size = size;