dhcpv6-ia: fix realloc bug
authorDavid Härdeman <[email protected]>
Thu, 27 Nov 2025 10:35:09 +0000 (11:35 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Thu, 27 Nov 2025 13:09:56 +0000 (14:09 +0100)
Commit b9db4d7061a08bf82a25222074065cce71973d0c introduced a bug, the
"hostname" variable used for the realloc would shadow the real hostname
defined at the beginning of the function. Fix this by using a different
variable name.

Fixes: b9db4d7061a0 ("dhcpv6: handle realloc failure")
Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/326
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv6-ia.c

index 32b652dd38df8d07d5f808584997111632867043..6361c313511c3faaff125c01c056297ae00ec823 100644 (file)
@@ -1236,9 +1236,9 @@ proceed:
                                    hdr->msg_type == DHCPV6_MSG_REQUEST ||
                                    hdr->msg_type == DHCPV6_MSG_REBIND)) {
                                if ((!(a->flags & OAF_STATIC) || !a->hostname) && hostname_len > 0) {
-                                       char *hostname = realloc(a->hostname, hostname_len + 1);
-                                       if (hostname) {
-                                               a->hostname = hostname;
+                                       char *tmp = realloc(a->hostname, hostname_len + 1);
+                                       if (tmp) {
+                                               a->hostname = tmp;
                                                memcpy(a->hostname, hostname, hostname_len);
                                                a->hostname[hostname_len] = 0;