1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

host_strduptrim: support RFC 4007 address literals.

I'd never even heard of these before. We don't need to do anything
unusual with these when passing them to our own getaddrinfo, but
host_strduptrim considered them a violation of its expectations about
what an IPv6 literal looked like, and hence wasn't stripping square
brackets off one. So a port-forwarding command-line option such as
'-L 12345:[fe80::%eth0]:22' would cause the address string in the
direct-tcpip CHANNEL_OPEN packet to be "[fe80::%eth0]" instead of the
correct "fe80::%eth0", leading to getaddrinfo failure on the SSH
server side.
This commit is contained in:
Simon Tatham 2019-03-09 08:10:02 +00:00
parent d2ddb2fdf4
commit 71a3e7da9e

14
utils.c
View File

@ -207,11 +207,21 @@ char *host_strduptrim(const char *s)
break; break;
p++; p++;
} }
if (*p == '%') {
/*
* This delimiter character introduces an RFC 4007 scope
* id suffix (e.g. suffixing the address literal with
* %eth1 or %2 or some such). There's no syntax
* specification for the scope id, so just accept anything
* except the closing ].
*/
p += strcspn(p, "]");
}
if (*p == ']' && !p[1] && colons > 1) { if (*p == ']' && !p[1] && colons > 1) {
/* /*
* This looks like an IPv6 address literal (hex digits and * This looks like an IPv6 address literal (hex digits and
* at least two colons, contained in square brackets). * at least two colons, plus optional scope id, contained
* Trim off the brackets. * in square brackets). Trim off the brackets.
*/ */
return dupprintf("%.*s", (int)(p - (s+1)), s+1); return dupprintf("%.*s", (int)(p - (s+1)), s+1);
} }