1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Use the new host_str* functions to improve IPv6 literal support.

I've gone through everywhere we handle host names / addresses (on
command lines, in PuTTY config, in port forwarding, in X display
names, in host key storage...) and tried to make them handle IPv6
literals sensibly, by using the host_str* functions I introduced in my
previous commit. Generally it's now OK to use a bracketed IPv6 literal
anywhere a hostname might have been valid; in a few cases where no
ambiguity exists (e.g. no :port suffix is permitted anyway)
unbracketed IPv6 literals are also acceptable.

[originally from svn r10120]
This commit is contained in:
Simon Tatham
2014-01-25 15:58:54 +00:00
parent 0348f57077
commit 8da4fa5063
14 changed files with 65 additions and 78 deletions

View File

@ -548,8 +548,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
q += 2;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
p += host_strcspn(p, ":/");
c = *p;
if (*p)
*p++ = '\0';
@ -614,15 +613,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
/*
* Trim a colon suffix off the hostname if it's there. In
* order to protect IPv6 address literals against this
* treatment, we do not do this if there's _more_ than one
* colon.
* order to protect unbracketed IPv6 address literals
* against this treatment, we do not do this if there's
* _more_ than one colon.
*/
{
char *c = strchr(host, ':');
char *c = host_strchr(host, ':');
if (c) {
char *d = strchr(c+1, ':');
char *d = host_strchr(c+1, ':');
if (!d)
*c = '\0';
}

View File

@ -527,7 +527,13 @@ SockAddr sk_namelookup(const char *host, char **canonicalname,
memset(&hints, 0, sizeof(hints));
hints.ai_family = hint_family;
hints.ai_flags = AI_CANONNAME;
if ((err = p_getaddrinfo(host, NULL, &hints, &ret->ais)) == 0)
{
/* strip [] on IPv6 address literals */
char *trimmed_host = host_strduptrim(host);
err = p_getaddrinfo(trimmed_host, NULL, &hints, &ret->ais);
sfree(trimmed_host);
}
if (err == 0)
ret->resolved = TRUE;
} else
#endif

View File

@ -382,8 +382,7 @@ int main(int argc, char **argv)
q += 2;
conf_set_int(conf, CONF_protocol, PROT_TELNET);
p = q;
while (*p && *p != ':' && *p != '/')
p++;
p += host_strcspn(p, ":/");
c = *p;
if (*p)
*p++ = '\0';
@ -524,7 +523,7 @@ int main(int argc, char **argv)
/*
* Trim off a colon suffix if it's there.
*/
host[strcspn(host, ":")] = '\0';
host[host_strcspn(host, ":")] = '\0';
/*
* Remove any remaining whitespace.