diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2023-02-08 13:16:53 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2023-03-14 17:16:57 +0000 |
| commit | 19aba210e1a1b5999bff10cccab5a277060c4d46 (patch) | |
| tree | ae14a50e31d9a03ab8e75e331f1cdf75525b91a8 | |
| parent | 96ab5023fd4b7de7df2627ce7c495292c468ba72 (diff) | |
ssh: fix leak and apply style(9) to hostname canonicalization
Fixes: bf2e2524a2ce ("ssh: canonicize the host name before...")
Fixes: 3e74849a1ee2 ("ssh: canonicize the host name before...")
Reviewed by: rew
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D38441
| -rw-r--r-- | crypto/openssh/ssh.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/crypto/openssh/ssh.c b/crypto/openssh/ssh.c index 21050ec342e0..7a44744e0029 100644 --- a/crypto/openssh/ssh.c +++ b/crypto/openssh/ssh.c @@ -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); } } |
