git: a2e65d45a5c6 - main - dhclient: correct struct ifreq allocation

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Thu, 04 Jul 2024 11:32:32 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2e65d45a5c6def93e1bc8652a6fe686a63fbdb8

commit a2e65d45a5c6def93e1bc8652a6fe686a63fbdb8
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2024-07-04 11:27:10 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2024-07-04 11:27:10 +0000

    dhclient: correct struct ifreq allocation
    
    ioctl commands such as BIOCSETIF take a struct ifreq and due to
    FreeBSD's ioctl implementation copy exactly sizeof(struct ifreq) bytes
    in so allocate that much space.
    
    The over-allocaton was harmless, but useless.
    
    Reported by:    def
    Fixes:          e2dc8d789f68a dhclient: do not add 0.0.0.0 interface alias.
    Sponsored by:   DARPA, AFRL
    
    Reviewed by:    def
    Differential Revision:  https://reviews.freebsd.org/D45769
---
 sbin/dhclient/dispatch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index 310f477f8a4f..3108fe4365d1 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -76,7 +76,6 @@ discover_interfaces(struct interface_info *iface)
 {
 	struct ifaddrs *ifap, *ifa;
 	struct ifreq *tif;
-	int len = IFNAMSIZ + sizeof(struct sockaddr_storage);
 
 	if (getifaddrs(&ifap) != 0)
 		error("getifaddrs failed");
@@ -119,7 +118,7 @@ discover_interfaces(struct interface_info *iface)
 			    LLADDR(foo), foo->sdl_alen);
 		}
 		if (!iface->ifp) {
-			if ((tif = calloc(1, len)) == NULL)
+			if ((tif = calloc(1, sizeof(struct ifreq))) == NULL)
 				error("no space to remember ifp");
 			strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
 			iface->ifp = tif;