Fix possible gethostbyname-related overflows as pointed out in

PR#bin/2585 .
This commit is contained in:
Bill Fenner 1997-02-09 22:32:04 +00:00
parent 81eb579301
commit de5ae7f25a
3 changed files with 4 additions and 3 deletions

View File

@ -826,7 +826,7 @@ u_int32 host_addr(name)
struct hostent *e = gethostbyname(name);
int addr;
if (e)
if (e && e->h_length == sizeof(addr))
memcpy(&addr, e->h_addr_list[0], e->h_length);
else {
addr = inet_addr(name);

View File

@ -383,7 +383,7 @@ main(argc, argv)
} else
hp = gethostbyname(host);
if (hp == NULL) {
if (hp == NULL || hp->h_length != sizeof(target_addr)) {
fprintf(stderr, "mrinfo: %s: no such host\n", argv[0]);
exit(1);
}

View File

@ -759,7 +759,8 @@ host_addr(name)
*op = '\0';
if (dots <= 0) e = gethostbyname(name);
if (e) memcpy((char *)&addr, e->h_addr_list[0], e->h_length);
if (e && e->h_length == sizeof(addr))
memcpy((char *)&addr, e->h_addr_list[0], e->h_length);
else {
addr = inet_addr(buf);
if (addr == -1 || (IN_MULTICAST(addr) && dots)) {