ssh: fix leak and apply style(9) to hostname canonicalization

Fixes:		bf2e2524a2 ("ssh: canonicize the host name before...")
Fixes:		3e74849a1e ("ssh: canonicize the host name before...")
Reviewed by:	rew
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38441
This commit is contained in:
Ed Maste 2023-02-08 08:16:53 -05:00
parent 96ab5023fd
commit 19aba210e1

View File

@ -1388,18 +1388,21 @@ main(int ac, char **av)
cinfo->locuser = xstrdup(pw->pw_name);
/* Find canonic host name. */
if (strchr(host, '.') == 0) {
if (strchr(host, '.') == NULL) {
struct addrinfo hints;
struct addrinfo *ai = NULL;
int errgai;
memset(&hints, 0, sizeof(hints));
hints.ai_family = options.address_family;
hints.ai_flags = AI_CANONNAME;
hints.ai_socktype = SOCK_STREAM;
errgai = getaddrinfo(host, NULL, &hints, &ai);
if (errgai == 0) {
if (ai->ai_canonname != NULL)
if (ai->ai_canonname != NULL) {
free(host);
host = xstrdup(ai->ai_canonname);
}
freeaddrinfo(ai);
}
}