config: fix realloc() handling for the "upstream" option
authorDavid Härdeman <[email protected]>
Sun, 23 Nov 2025 13:50:00 +0000 (14:50 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Thu, 27 Nov 2025 07:24:38 +0000 (08:24 +0100)
Deal properly with realloc() failure.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/320
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c

index 9a092248797e5048c41e459bb9ffd4f3864e5e04..6a8796054c05d0e7393957fe682facdbb02178cc 100644 (file)
@@ -1227,16 +1227,17 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if (overwrite && (c = tb[IFACE_ATTR_UPSTREAM])) {
                struct blob_attr *cur;
                unsigned rem;
+               char *tmp;
 
                blobmsg_for_each_attr(cur, c, rem) {
                        if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
                                continue;
 
-                       iface->upstream = realloc(iface->upstream,
-                                       iface->upstream_len + blobmsg_data_len(cur));
-                       if (!iface->upstream)
+                       tmp = realloc(iface->upstream, iface->upstream_len + blobmsg_data_len(cur));
+                       if (!tmp)
                                goto err;
 
+                       iface->upstream = tmp;
                        memcpy(iface->upstream + iface->upstream_len, blobmsg_get_string(cur), blobmsg_data_len(cur));
                        iface->upstream_len += blobmsg_data_len(cur);
                }