From 40dc9eceb78ac558b235a128241b1a4d2819f15f Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sat, 9 Mar 2024 23:31:58 +0800 Subject: [PATCH] utils: fix crash when using MAC addresses as client identifiers --- src/util.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 4a911ffd16..611bac5aac 100644 --- a/src/util.c +++ b/src/util.c @@ -908,15 +908,16 @@ int netlink_get_neighbors(int family, continue; } - unsigned int rtalen = len; - for (nlh = (struct nlmsghdr *)buf; NLMSG_OK(nlh, rtalen); nlh = NLMSG_NEXT(nlh, rtalen)) { + int nlh_len = len; + for (nlh = (struct nlmsghdr *)buf; NLMSG_OK(nlh, nlh_len); nlh = NLMSG_NEXT(nlh, nlh_len)) { ndm = NLMSG_DATA(nlh); struct rtattr *rta = RTM_RTA(ndm); const uint8_t *mac = NULL; const uint8_t *net_addr = NULL; int net_addr_len = 0; + int rta_len = RTM_PAYLOAD(nlh); - for (; RTA_OK(rta, rtalen); rta = RTA_NEXT(rta, rtalen)) { + for (; RTA_OK(rta, rta_len); rta = RTA_NEXT(rta, rta_len)) { if (rta->rta_type == NDA_DST) { if (ndm->ndm_family == AF_INET) { struct in_addr *addr = RTA_DATA(rta);