Fix crash in gdomap when an invalid hostname is given for the -M option

This commit is contained in:
Wolfgang Lux 2019-03-18 12:12:01 +01:00
parent dc481825ec
commit c3b7a69968
2 changed files with 14 additions and 8 deletions

View file

@ -1,3 +1,8 @@
2019-03-18 Wolfgang Lux <wolfgang.lux@gmail.com>
* Tools/gdomap.c:
Fix crash in donames() when getaddrinfo returns an error.
2019-02-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unidoce.m: comment-out left-over debug logging.

View file

@ -4312,17 +4312,18 @@ donames(const char *host)
memset(&hints, '\0', sizeof(hints));
hints.ai_family = AF_INET;
if (getaddrinfo(host, NULL, &hints, &info) != 0 && first_dot != 0)
if ((err = getaddrinfo(host, NULL, &hints, &info) != 0) && first_dot != 0)
{
*first_dot = '.';
if ((err = getaddrinfo(host, NULL, &hints, &info)) != 0)
{
snprintf(ebuf, sizeof(ebuf),
"getaddrinfo('%s') failed: %s", host, gai_strerror(err));
gdomap_log(LOG_ERR);
return;
}
err = getaddrinfo(host, NULL, &hints, &info);
}
if (err != 0)
{
snprintf(ebuf, sizeof(ebuf),
"getaddrinfo('%s') failed: %s", host, gai_strerror(err));
gdomap_log(LOG_ERR);
return;
}
sin.sin_addr = ((struct sockaddr_in *)info->ai_addr)->sin_addr;
freeaddrinfo(info);
}