--- ./panel-plugin/wormulon/openbsd.c-orig Thu Feb 9 14:42:29 2017 +++ ./panel-plugin/wormulon/openbsd.c Wed Sep 13 12:54:16 2017 @@ -41,7 +41,6 @@ struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; size_t needed; - char s[32]; if (sysctl(data->mib_name1, 6, NULL, &needed, NULL, 0) < 0) return FALSE; @@ -78,18 +77,25 @@ if (ifm->ifm_flags & IFF_UP) { sdl = (struct sockaddr_dl *)(ifm + 1); - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; - if (strcmp(s, data->ifdata.if_name) != 0) - continue; - else + + /* OpenBSD netstat code checks > 0, so do so here */ + if (sdl->sdl_nlen > 0) { - validinterface = TRUE; - break; /* stop searching */ + size_t nlen = sdl->sdl_nlen; + + if (strncmp(sdl->sdl_data, data->ifdata.if_name, nlen) != 0) + continue; + if (data->ifdata.if_name[nlen] != '\0') + continue; } + else + continue; + + validinterface = TRUE; + break; /* stop searching */ } } return validinterface; @@ -108,7 +114,6 @@ char *lim, *next; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; - char s[32]; size_t needed; unsigned long rx_o, tx_o; @@ -122,7 +127,7 @@ if (data->buf2 == NULL) return 1; data->alloc2 = needed; - } + } if (sysctl(data->mib_name2, 6, data->buf2, &needed, NULL, 0) < 0) return 1; @@ -149,10 +154,19 @@ /* search for the right network interface */ if (sdl->sdl_family != AF_LINK) continue; - if (strcmp(sdl->sdl_data, data->ifdata.if_name) != 0) + + /* OpenBSD netstat code checks > 0, so do so here */ + if (sdl->sdl_nlen > 0) + { + size_t nlen = sdl->sdl_nlen; + + if (strncmp(sdl->sdl_data, data->ifdata.if_name, nlen) != 0) + continue; + if (data->ifdata.if_name[nlen] != '\0') + continue; + } + else continue; - strncpy(s, sdl->sdl_data, sdl->sdl_nlen); - s[sdl->sdl_nlen] = '\0'; rx_o = data->stats.rx_bytes; tx_o = data->stats.tx_bytes; /* write stats */