From f3ffd1700739b9a4ec7b2ba0427409289c80735f Mon Sep 17 00:00:00 2001 From: bi4k8 Date: Mon, 12 Dec 2022 19:15:07 +0000 Subject: [PATCH] linux: remove nonsensical ip_addr loop break cond This checks if a pointer offset from a heap-allocated buffer is NULL, which is only true if the buffer is NULL and the offset is zero. It appears to be attempting to check if an entry in an array of pointers is zero before dereferencing that entry, but the SIOCGIFCONF ioctl actually writes `struct ifreq` entries (not pointers to them) into the `ifc_buf` buffer. Furthermore, because `ifc_buf` is in a union with `struct ifreq *ifc_req`, we can simply access `ifc_req` instead of casting `ifc_buf` each time. --- src/linux.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/linux.cc b/src/linux.cc index 14b93148..c26c847f 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -578,11 +578,9 @@ void update_net_interfaces(FILE *net_dev_fp, bool is_first_update, for (unsigned int k = 0; k < conf.ifc_len / sizeof(struct ifreq); k++) { struct net_stat *ns2; - if (!(((struct ifreq *)conf.ifc_buf) + k)) break; - - ns2 = get_net_stat(((struct ifreq *)conf.ifc_buf)[k].ifr_ifrn.ifrn_name, + ns2 = get_net_stat(conf.ifc_req[k].ifr_ifrn.ifrn_name, nullptr, NULL); - ns2->addr = ((struct ifreq *)conf.ifc_buf)[k].ifr_ifru.ifru_addr; + ns2->addr = conf.ifc_req[k].ifr_ifru.ifru_addr; char temp_addr[18]; snprintf(temp_addr, sizeof(temp_addr), "%u.%u.%u.%u, ", ns2->addr.sa_data[2] & 255, ns2->addr.sa_data[3] & 255,