libc: fix buffer overrun in getrpcport(3)

Reviewed By:	markj
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D27332
This commit is contained in:
Edward Tomasz Napierala 2021-01-31 21:41:55 +00:00
parent b8073b3c74
commit 5299d64b2b
1 changed files with 3 additions and 3 deletions

View File

@ -62,14 +62,14 @@ getrpcport(char *host, int prognum, int versnum, int proto)
assert(host != NULL);
if ((hp = gethostbyname(host)) == NULL)
if ((hp = gethostbyname2(host, AF_INET)) == NULL)
return (0);
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(struct sockaddr_in);
addr.sin_family = AF_INET;
addr.sin_port = 0;
if (hp->h_length > addr.sin_len)
hp->h_length = addr.sin_len;
if (hp->h_length > sizeof(addr.sin_addr.s_addr))
hp->h_length = sizeof(addr.sin_addr.s_addr);
memcpy(&addr.sin_addr.s_addr, hp->h_addr, (size_t)hp->h_length);
/* Inconsistent interfaces need casts! :-( */
return (pmap_getport(&addr, (u_long)prognum, (u_long)versnum,