use stack buffer instead of heap for sigar_net_interface_name_get
This commit is contained in:
parent
4655d5e3df
commit
73c3c287f7
|
@ -2668,15 +2668,14 @@ static int netif_hash(char *s)
|
||||||
#define IF_TYPE_IEEE80211 71
|
#define IF_TYPE_IEEE80211 71
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *
|
static int
|
||||||
sigar_net_interface_name_get(sigar_t *sigar, MIB_IFROW *ifr, PIP_ADAPTER_ADDRESSES address_list)
|
sigar_net_interface_name_get(sigar_t *sigar, MIB_IFROW *ifr, PIP_ADAPTER_ADDRESSES address_list, char *name)
|
||||||
{
|
{
|
||||||
char *match = NULL;
|
|
||||||
PIP_ADAPTER_ADDRESSES iter;
|
PIP_ADAPTER_ADDRESSES iter;
|
||||||
int lpc = 0;
|
int lpc = 0;
|
||||||
|
|
||||||
if (address_list == NULL) {
|
if (address_list == NULL) {
|
||||||
return NULL;
|
return SIGAR_ENOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (iter = address_list; iter != NULL; iter = iter->Next) {
|
for (iter = address_list; iter != NULL; iter = iter->Next) {
|
||||||
|
@ -2687,14 +2686,13 @@ sigar_net_interface_name_get(sigar_t *sigar, MIB_IFROW *ifr, PIP_ADAPTER_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpc == iter->PhysicalAddressLength) {
|
if (lpc == iter->PhysicalAddressLength) {
|
||||||
match = malloc(MAX_INTERFACE_NAME_LEN);
|
wcstombs(name, iter->FriendlyName, MAX_INTERFACE_NAME_LEN);
|
||||||
wcstombs(match, iter->FriendlyName, MAX_INTERFACE_NAME_LEN);
|
name[MAX_INTERFACE_NAME_LEN-1] = '\0';
|
||||||
match[MAX_INTERFACE_NAME_LEN-1] = 0;
|
return SIGAR_OK;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return SIGAR_ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
SIGAR_DECLARE(int)
|
SIGAR_DECLARE(int)
|
||||||
|
@ -2742,22 +2740,18 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||||
int key;
|
int key;
|
||||||
MIB_IFROW *ifr = ift->table + i;
|
MIB_IFROW *ifr = ift->table + i;
|
||||||
sigar_cache_entry_t *entry;
|
sigar_cache_entry_t *entry;
|
||||||
char *friendly = NULL;
|
|
||||||
|
status = SIGAR_ENOENT;
|
||||||
|
|
||||||
if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
|
if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
|
||||||
/* special-case */
|
/* special-case */
|
||||||
sprintf(name, NETIF_LA "%d", la++);
|
sprintf(name, NETIF_LA "%d", la++);
|
||||||
}
|
}
|
||||||
else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
|
else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
|
||||||
friendly = sigar_net_interface_name_get(sigar, ifr, address_list);
|
status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
|
||||||
if (friendly == NULL) {
|
if (status != SIGAR_OK) {
|
||||||
sprintf(name, "lo%d", lo++);
|
sprintf(name, "lo%d", lo++);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
snprintf(name, MAX_INTERFACE_NAME_LEN, "%s", friendly);
|
|
||||||
}
|
|
||||||
name[MAX_INTERFACE_NAME_LEN] = 0;
|
|
||||||
free(friendly);
|
|
||||||
}
|
}
|
||||||
else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
|
else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
|
||||||
(ifr->dwType == IF_TYPE_IEEE80211))
|
(ifr->dwType == IF_TYPE_IEEE80211))
|
||||||
|
@ -2765,17 +2759,12 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||||
if ((strstr(ifr->bDescr, "Scheduler") == NULL) &&
|
if ((strstr(ifr->bDescr, "Scheduler") == NULL) &&
|
||||||
(strstr(ifr->bDescr, "Filter") == NULL))
|
(strstr(ifr->bDescr, "Filter") == NULL))
|
||||||
{
|
{
|
||||||
friendly = sigar_net_interface_name_get(sigar, ifr, address_list);
|
status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (friendly == NULL) {
|
if (status != SIGAR_OK) {
|
||||||
snprintf(name, ifr->dwDescrLen, "%s", ifr->bDescr);
|
snprintf(name, ifr->dwDescrLen, "%s", ifr->bDescr);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
snprintf(name, MAX_INTERFACE_NAME_LEN, "%s", friendly);
|
|
||||||
}
|
|
||||||
name[MAX_INTERFACE_NAME_LEN] = 0;
|
|
||||||
free(friendly);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue; /*XXX*/
|
continue; /*XXX*/
|
||||||
|
|
Loading…
Reference in New Issue