(SIGAR-137) sdl_data isn't 0-terminated

fixed 2 more places where sdl_data is used as it would be 0-term'ed
  and doesn't honour sdl_nlen
This commit is contained in:
Jan Kneschke 2009-08-09 14:22:39 +02:00 committed by Doug MacEachern
parent 9149e907ef
commit 079dd9b09f
1 changed files with 9 additions and 4 deletions

View File

@ -2487,7 +2487,11 @@ static int sigar_ifmsg_init(sigar_t *sigar)
return SIGAR_OK;
}
static int has_ifaddr(char *name)
/**
* @param name name of the interface
* @param name_len length of name (w/o \0)
*/
static int has_ifaddr(char *name, size_t name_len)
{
int sock, status;
struct ifreq ifr;
@ -2495,7 +2499,8 @@ static int has_ifaddr(char *name)
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
return errno;
}
SIGAR_SSTRCPY(ifr.ifr_name, name);
strncpy(ifr.ift_name, name, MIN(sizeof(ifr.ift_name) - 1, name_len));
ifr.ift_name[MIN(sizeof(ifr.ift_name) - 1, name_len)] = '\0';
if (ioctl(sock, SIOCGIFADDR, &ifr) == 0) {
status = SIGAR_OK;
}
@ -2545,7 +2550,7 @@ static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter)
switch (iter->type) {
case IFMSG_ITER_LIST:
if (sdl->sdl_type == IFT_OTHER) {
if (has_ifaddr(sdl->sdl_data) != SIGAR_OK) {
if (has_ifaddr(sdl->sdl_data, sdl->sdl_nlen) != SIGAR_OK) {
break;
}
}
@ -2566,7 +2571,7 @@ static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter)
break;
case IFMSG_ITER_GET:
if (strEQ(iter->name, sdl->sdl_data)) {
if (strlen(iter->name) == sdl->sdl_nlen && 0 == memcmp(iter->name, sdl->sdl_data, sdl->sdl_nlen)) {
iter->data.ifm = ifm;
return SIGAR_OK;
}