1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-10-27 13:52:20 +03:00

Fix regression in IPv6 addresses in hostname parsing

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2023-12-22 10:32:40 +01:00
parent b3de3a3335
commit 4f997aee7c
4 changed files with 23 additions and 18 deletions

View File

@@ -162,9 +162,10 @@ int ssh_config_get_yesno(char **str, int notfound)
}
int ssh_config_parse_uri(const char *tok,
char **username,
char **hostname,
char **port)
char **username,
char **hostname,
char **port,
bool ignore_port)
{
char *endp = NULL;
long port_n;
@@ -210,12 +211,17 @@ int ssh_config_parse_uri(const char *tok,
if (endp == NULL) {
goto error;
}
} else {
/* Hostnames or aliases expand to the last colon or to the end */
} else if (!ignore_port) {
/* Hostnames or aliases expand to the last colon (if port is requested)
* or to the end */
endp = strrchr(tok, ':');
if (endp == NULL) {
endp = strchr(tok, '\0');
}
} else {
/* If no port is requested, expand to the end of line
* (to accommodate the IPv6 addresses) */
endp = strchr(tok, '\0');
}
if (tok == endp) {
/* Zero-length hostnames are not valid */