type = p[1]; /* 'L' or 'R' */
- q = qq = strchr(value, ':');
+ q = qq = host_strchr(value, ':');
while (qq) {
- char *qqq = strchr(qq+1, ':');
+ char *qqq = host_strchr(qq+1, ':');
if (qqq)
q = qq;
qq = qqq;
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
SAVEABLE(0);
- portp = strchr(value, ':');
+ portp = host_strchr(value, ':');
if (!portp) {
cmdline_error("-nc expects argument of form 'host:port'");
return ret;
}
if (*type != 'D') {
val = dlg_editbox_get(pfd->destbox, dlg);
- if (!*val || !strchr(val, ':')) {
+ if (!*val || !host_strchr(val, ':')) {
dlg_error_msg(dlg,
"You need to specify a destination address\n"
"in the form \"host.name:port\"");
bump("Empty host name");
/*
- * Remove fiddly bits of address: remove a colon suffix, and
- * the square brackets around an IPv6 literal address.
+ * Remove a colon suffix.
*/
- if (host[0] == '[') {
- host++;
- host[strcspn(host, "]")] = '\0';
- } else {
- host[strcspn(host, ":")] = '\0';
- }
+ host[host_strcspn(host, ":")] = '\0';
/*
* If we haven't loaded session details already (e.g., from -load),
if (str[0] == '\0' || str[0] == ':' ||
(str[0] != '[' && str[1] == ':'))
return (NULL);
- while (*str != '\0' && *str != ':' && *str != '/' && *str != '\\') {
- if (*str == '[') {
- /* Skip over IPv6 literal addresses
- * (eg: 'jeroen@[2001:db8::1]:myfile.txt') */
- char *ipv6_end = strchr(str, ']');
- if (ipv6_end) {
- str = ipv6_end;
- }
- }
- str++;
- }
+ str += host_strcspn(str, ":/\\");
if (*str == ':')
return (str);
else
sfree(*realhost);
*realhost = dupstr(loghost);
- colon = strrchr(*realhost, ':');
- if (colon) {
- /*
- * FIXME: if we ever update this aspect of ssh.c for
- * IPv6 literal management, this should change in line
- * with it.
- */
+
+ colon = host_strrchr(*realhost, ':');
+ if (colon)
*colon++ = '\0';
- }
}
return NULL;
sfree(*realhost);
*realhost = dupstr(loghost);
- colon = strrchr(*realhost, ':');
- if (colon) {
- /*
- * FIXME: if we ever update this aspect of ssh.c for
- * IPv6 literal management, this should change in line
- * with it.
- */
+
+ colon = host_strrchr(*realhost, ':');
+ if (colon)
*colon++ = '\0';
- }
}
/*
loghost = conf_get_str(ssh->conf, CONF_loghost);
if (*loghost) {
- char *colon;
+ char *tmphost;
+ char *colon;
- ssh->savedhost = dupstr(loghost);
+ tmphost = dupstr(loghost);
ssh->savedport = 22; /* default ssh port */
/*
- * A colon suffix on savedhost also lets us affect
+ * A colon suffix on the hostname string also lets us affect
* savedport.
- *
- * (FIXME: do something about IPv6 address literals here.)
*/
- colon = strrchr(ssh->savedhost, ':');
+ colon = host_strrchr(tmphost, ':');
if (colon) {
*colon++ = '\0';
if (*colon)
ssh->savedport = atoi(colon);
}
+
+ ssh->savedhost = host_strduptrim(tmphost);
+ sfree(tmphost);
} else {
- ssh->savedhost = dupstr(host);
+ ssh->savedhost = host_strduptrim(host);
if (port < 0)
port = 22; /* default ssh port */
ssh->savedport = port;
if (*kp == 'L' || *kp == 'R')
type = *kp++;
- if ((kp2 = strchr(kp, ':')) != NULL) {
+ if ((kp2 = host_strchr(kp, ':')) != NULL) {
/*
* There's a colon in the middle of the source port
* string, which means that the part before it is
* actually a source address.
*/
- saddr = dupprintf("%.*s", (int)(kp2 - kp), kp);
+ char *saddr_tmp = dupprintf("%.*s", (int)(kp2 - kp), kp);
+ saddr = host_strduptrim(saddr_tmp);
+ sfree(saddr_tmp);
sports = kp2+1;
} else {
saddr = NULL;
} else {
/* ordinary forwarding */
vp = val;
- vp2 = vp + strcspn(vp, ":");
+ vp2 = vp + host_strcspn(vp, ":");
host = dupprintf("%.*s", (int)(vp2 - vp), vp);
if (vp2)
vp2++;
PKT_END);
} else {
pktout = ssh2_chanopen_init(c, "direct-tcpip");
- ssh2_pkt_addstring(pktout, hostname);
+ {
+ char *trimmed_host = host_strduptrim(hostname);
+ ssh2_pkt_addstring(pktout, trimmed_host);
+ sfree(trimmed_host);
+ }
ssh2_pkt_adduint32(pktout, port);
/*
* We make up values for the originator data; partly it's
sfree(*realhost);
*realhost = dupstr(loghost);
- colon = strrchr(*realhost, ':');
- if (colon) {
- /*
- * FIXME: if we ever update this aspect of ssh.c for
- * IPv6 literal management, this should change in line
- * with it.
- */
+
+ colon = host_strrchr(*realhost, ':');
+ if (colon)
*colon++ = '\0';
- }
}
return NULL;
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
- err = getaddrinfo(host, NULL, &hints, &ret->ais);
+ {
+ char *trimmed_host = host_strduptrim(host); /* strip [] on literals */
+ err = getaddrinfo(trimmed_host, NULL, &hints, &ret->ais);
+ sfree(trimmed_host);
+ }
if (err != 0) {
ret->error = gai_strerror(err);
return ret;
hints.ai_next = NULL;
assert(port >= 0 && port <= 99999);
sprintf(portstr, "%d", port);
- retcode = getaddrinfo(srcaddr, portstr, &hints, &ai);
+ {
+ char *trimmed_addr = host_strduptrim(srcaddr);
+ retcode = getaddrinfo(trimmed_addr, portstr, &hints, &ai);
+ sfree(trimmed_addr);
+ }
if (retcode == 0) {
addr = (union sockaddr_union *)ai->ai_addr;
addrlen = ai->ai_addrlen;
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';
/*
* Trim off a colon suffix if it's there.
*/
- host[strcspn(host, ":")] = '\0';
+ host[host_strcspn(host, ":")] = '\0';
/*
* Remove any remaining whitespace.
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';
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';
/*
* 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';
}
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
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';
/*
* Trim off a colon suffix if it's there.
*/
- host[strcspn(host, ":")] = '\0';
+ host[host_strcspn(host, ":")] = '\0';
/*
* Remove any remaining whitespace.
char *colon, *dot, *slash;
char *protocol, *hostname;
- colon = strrchr(localcopy, ':');
+ colon = host_strrchr(localcopy, ':');
if (!colon) {
sfree(disp);
sfree(localcopy);
{
int n;
- n = strcspn(display, ":");
+ n = host_strcspn(display, ":");
if (!display[n])
return 0;
n = strcspn(display, ".");