Bugzilla – Attachment 2453 Details for
Bug 2074
Host key verification incorrectly handles IPv6 addresses
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Canonicalise addresses when CanonicaliseHostnames enabled
canon-addr.diff (text/plain), 2.73 KB, created by
Damien Miller
on 2014-07-03 16:18:32 AEST
(
hide
)
Description:
Canonicalise addresses when CanonicaliseHostnames enabled
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2014-07-03 16:18:32 AEST
Size:
2.73 KB
patch
obsolete
>diff --git ssh.c ssh.c >index 17f6363..a92287f 100644 >--- ssh.c >+++ ssh.c >@@ -262,6 +262,61 @@ resolve_host(const char *name, int port, int logerr, char *cname, size_t clen) > } > > /* >+ * Attempt to resolve a numeric host address / port to a single address. >+ * Returns a canonical address string. >+ * Returns NULL on failure. >+ * NB. this function must operate with a options having undefined members. >+ */ >+static struct addrinfo * >+resolve_addr(const char *name, int port, char *caddr, size_t clen) >+{ >+ char addr[NI_MAXHOST], strport[NI_MAXSERV]; >+ struct addrinfo hints, *res; >+ int gaierr; >+ >+ if (port <= 0) >+ port = default_ssh_port(); >+ snprintf(strport, sizeof strport, "%u", port); >+ memset(&hints, 0, sizeof(hints)); >+ hints.ai_family = options.address_family == -1 ? >+ AF_UNSPEC : options.address_family; >+ hints.ai_socktype = SOCK_STREAM; >+ hints.ai_flags = AI_NUMERICHOST|AI_NUMERICSERV; >+ if ((gaierr = getaddrinfo(name, strport, &hints, &res)) != 0) { >+ debug2("%s: could not resolve name %.100s as address: %s", >+ __func__, name, ssh_gai_strerror(gaierr)); >+ return NULL; >+ } >+ if (res == NULL) { >+ debug("%s: getaddrinfo %.100s returned no addresses", >+ __func__, name); >+ return NULL; >+ } >+ if (res->ai_next != NULL) { >+ debug("%s: getaddrinfo %.100s returned multiple addresses", >+ __func__, name); >+ freeaddrinfo(res); >+ return NULL; >+ } >+ if ((gaierr = getnameinfo(res->ai_addr, res->ai_addrlen, >+ addr, sizeof(addr), NULL, 0, NI_NUMERICHOST)) != 0) { >+ debug("%s: Could not format address for name %.100s: %s", >+ __func__, name, ssh_gai_strerror(gaierr)); >+ freeaddrinfo(res); >+ return NULL; >+ } >+ if (strlcpy(caddr, addr, clen) >= clen) { >+ error("%s: host \"%s\" addr \"%s\" too long (max %lu)", >+ __func__, name, addr, (u_long)clen); >+ if (clen > 0) >+ *caddr = '\0'; >+ freeaddrinfo(res); >+ return NULL; >+ } >+ return res; >+} >+ >+/* > * Check whether the cname is a permitted replacement for the hostname > * and perform the replacement if it is. > * NB. this function must operate with a options having undefined members. >@@ -325,6 +380,19 @@ resolve_canonicalize(char **hostp, int port) > options.canonicalize_hostname != SSH_CANONICALISE_ALWAYS) > return NULL; > >+ /* Try numeric hostnames first */ >+ if ((addrs = resolve_addr(*hostp, port, >+ cname_target, sizeof(cname_target))) != NULL) { >+ debug2("%s: hostname %.100s is address", __func__, *hostp); >+ if (strcasecmp(*hostp, cname_target) != 0) { >+ debug2("%s: canonicalised address \"%s\" => \"%s\"", >+ __func__, *hostp, cname_target); >+ free(*hostp); >+ *hostp = xstrdup(cname_target); >+ } >+ return addrs; >+ } >+ > /* Don't apply canonicalization to sufficiently-qualified hostnames */ > ndots = 0; > for (cp = *hostp; *cp != '\0'; cp++) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 2074
:
2226
| 2453