dhcpv4: fix uninitialized hostname in some ubus events
authorMikael Magnusson <mikma@users.sourceforge.net>
Wed, 11 Aug 2021 15:04:54 +0000 (17:04 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Sun, 15 Aug 2021 15:34:55 +0000 (17:34 +0200)
The hostname buffer is uninitialized if the client doesn't provide
DHCPV4_OPT_HOSTNAME. Use hostname from the assignment which is present if
a static lease contains the hostname or if the client provides one, and
the hostname is valid. It's also used in the ubus ipv4leases method.

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
src/dhcpv4.c

index c3d16f56bb6262022c9f4984a4481bbb0e9e5af2..a3b0e33c7540df34af8a0b4c2c6e5ff54366df0d 100644 (file)
@@ -758,7 +758,7 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len,
 #ifdef WITH_UBUS
        if (reqmsg == DHCPV4_MSG_RELEASE)
                ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen,
-                                       &req->ciaddr, hostname, iface->ifname);
+                                       &req->ciaddr, a ? a->hostname : NULL, iface->ifname);
 #endif
        if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
                return;
@@ -915,7 +915,7 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len,
 #ifdef WITH_UBUS
        if (msg == DHCPV4_MSG_ACK)
                ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &reply.yiaddr,
-                                       hostname, iface->ifname);
+                                       a ? a->hostname : NULL, iface->ifname);
 #endif
 }