Check the size of the IP address reutrned from gethostbyname2, per PR
2578 from Julian A. Likely not strictly needed, but it doesn't hurt and protects ping against possible buffer overflows if the resolver were to return large IP addresses.
This commit is contained in:
parent
ddd79a9790
commit
1ffae4a6dd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23327
@ -45,7 +45,7 @@ static const char copyright[] =
|
|||||||
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
|
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
|
||||||
*/
|
*/
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id: ping.c,v 1.18 1997/03/02 06:32:40 imp Exp $";
|
"$Id: ping.c,v 1.19 1997/03/02 20:01:13 imp Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -324,6 +324,8 @@ main(argc, argv)
|
|||||||
target, hstrerror(h_errno));
|
target, hstrerror(h_errno));
|
||||||
|
|
||||||
to->sin_len = sizeof *to;
|
to->sin_len = sizeof *to;
|
||||||
|
if (hp->h_length > sizeof(to->sin_addr))
|
||||||
|
errx(1,"gethostbyname2 returned an illegal address");
|
||||||
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
|
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
|
||||||
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
|
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
|
||||||
hnamebuf[(sizeof hnamebuf) - 1] = '\0';
|
hnamebuf[(sizeof hnamebuf) - 1] = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user