ID: 256 - ipmitool could crash when IPv6 address is returned

gethostbyname() can't handle IPv6. Despite this fact it seems worth of
nothing to check whether gethostbyname() really returned AF_INET or
not. And that's what attached patch does, resp. in case IPv6 is
returned then ipmitool shoud/will terminate.
This commit is contained in:
Zdenek Styblik 2013-07-16 04:17:39 +00:00
parent 8a40297308
commit 9f51d8f188
4 changed files with 28 additions and 0 deletions

View File

@ -494,6 +494,13 @@ ipmi_dcmi_prnt_oobDiscover(struct ipmi_intf * intf)
s->hostname);
return -1;
}
if (host->h_addrtype != AF_INET) {
lprintf(LOG_ERR,
"Address lookup for %s failed. Got %s, expected IPv4 address.",
s->hostname,
(host->h_addrtype == AF_INET6) ? "IPv6" : "Unknown");
return (-1);
}
s->addr.sin_family = host->h_addrtype;
memcpy(&s->addr.sin_addr, host->h_addr, host->h_length);
}

View File

@ -437,6 +437,13 @@ ipmi_tsol_main(struct ipmi_intf * intf, int argc, char ** argv)
intf->session->hostname);
return -1;
}
if (host->h_addrtype != AF_INET) {
lprintf(LOG_ERR,
"Address lookup for %s failed. Got %s, expected IPv4 address.",
intf->session->hostname,
(host->h_addrtype == AF_INET6) ? "IPv6" : "Unknown");
return (-1);
}
intf->session->addr.sin_family = host->h_addrtype;
memcpy(&intf->session->addr.sin_addr, host->h_addr, host->h_length);
}

View File

@ -2045,6 +2045,13 @@ ipmi_lan_open(struct ipmi_intf * intf)
s->hostname);
return -1;
}
if (host->h_addrtype != AF_INET) {
lprintf(LOG_ERR,
"Address lookup for %s failed. Got %s, expected IPv4 address.",
s->hostname,
(host->h_addrtype == AF_INET6) ? "IPv6" : "Unknown");
return (-1);
}
s->addr.sin_family = host->h_addrtype;
memcpy(&s->addr.sin_addr, host->h_addr, host->h_length);
}

View File

@ -3387,6 +3387,13 @@ ipmi_lanplus_open(struct ipmi_intf * intf)
session->hostname);
return -1;
}
if (host->h_addrtype != AF_INET) {
lprintf(LOG_ERR,
"Address lookup for %s failed. Got %s, expected IPv4 address.",
session->hostname,
(host->h_addrtype == AF_INET6) ? "IPv6" : "Unknown");
return (-1);
}
addr.sin_family = host->h_addrtype;
memcpy(&addr.sin_addr, host->h_addr, host->h_length);
}