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:
@@ -30,6 +30,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
char *ssh_config_get_cmd(char **str);
|
char *ssh_config_get_cmd(char **str);
|
||||||
|
|
||||||
char *ssh_config_get_token(char **str);
|
char *ssh_config_get_token(char **str);
|
||||||
@@ -49,14 +51,17 @@ int ssh_config_get_yesno(char **str, int notfound);
|
|||||||
* be stored or NULL if we do not care about the result.
|
* be stored or NULL if we do not care about the result.
|
||||||
* @param[out] port Pointer to the location, where the new port will
|
* @param[out] port Pointer to the location, where the new port will
|
||||||
* be stored or NULL if we do not care about the result.
|
* be stored or NULL if we do not care about the result.
|
||||||
|
* @param[in] ignore_port Set to true if the we should not attempt to parse
|
||||||
|
* port number.
|
||||||
*
|
*
|
||||||
* @returns SSH_OK if the provided string is in format of SSH URI,
|
* @returns SSH_OK if the provided string is in format of SSH URI,
|
||||||
* SSH_ERROR on failure
|
* SSH_ERROR on failure
|
||||||
*/
|
*/
|
||||||
int ssh_config_parse_uri(const char *tok,
|
int ssh_config_parse_uri(const char *tok,
|
||||||
char **username,
|
char **username,
|
||||||
char **hostname,
|
char **hostname,
|
||||||
char **port);
|
char **port,
|
||||||
|
bool ignore_port);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing)
|
|||||||
}
|
}
|
||||||
if (parse_entry) {
|
if (parse_entry) {
|
||||||
/* We actually care only about the first item */
|
/* We actually care only about the first item */
|
||||||
rv = ssh_config_parse_uri(cp, &username, &hostname, &port);
|
rv = ssh_config_parse_uri(cp, &username, &hostname, &port, false);
|
||||||
/* The rest of the list needs to be passed on */
|
/* The rest of the list needs to be passed on */
|
||||||
if (endp != NULL) {
|
if (endp != NULL) {
|
||||||
next = strdup(endp + 1);
|
next = strdup(endp + 1);
|
||||||
@@ -475,7 +475,7 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* The rest is just sanity-checked to avoid failures later */
|
/* The rest is just sanity-checked to avoid failures later */
|
||||||
rv = ssh_config_parse_uri(cp, NULL, NULL, NULL);
|
rv = ssh_config_parse_uri(cp, NULL, NULL, NULL, false);
|
||||||
}
|
}
|
||||||
if (rv != SSH_OK) {
|
if (rv != SSH_OK) {
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
@@ -162,9 +162,10 @@ int ssh_config_get_yesno(char **str, int notfound)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ssh_config_parse_uri(const char *tok,
|
int ssh_config_parse_uri(const char *tok,
|
||||||
char **username,
|
char **username,
|
||||||
char **hostname,
|
char **hostname,
|
||||||
char **port)
|
char **port,
|
||||||
|
bool ignore_port)
|
||||||
{
|
{
|
||||||
char *endp = NULL;
|
char *endp = NULL;
|
||||||
long port_n;
|
long port_n;
|
||||||
@@ -210,12 +211,17 @@ int ssh_config_parse_uri(const char *tok,
|
|||||||
if (endp == NULL) {
|
if (endp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!ignore_port) {
|
||||||
/* Hostnames or aliases expand to the last colon or to the end */
|
/* Hostnames or aliases expand to the last colon (if port is requested)
|
||||||
|
* or to the end */
|
||||||
endp = strrchr(tok, ':');
|
endp = strrchr(tok, ':');
|
||||||
if (endp == NULL) {
|
if (endp == NULL) {
|
||||||
endp = strchr(tok, '\0');
|
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) {
|
if (tok == endp) {
|
||||||
/* Zero-length hostnames are not valid */
|
/* Zero-length hostnames are not valid */
|
||||||
|
|||||||
@@ -634,17 +634,11 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
|||||||
ssh_set_error_invalid(session);
|
ssh_set_error_invalid(session);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
char *username = NULL, *hostname = NULL, *port = NULL;
|
char *username = NULL, *hostname = NULL;
|
||||||
rc = ssh_config_parse_uri(value, &username, &hostname, &port);
|
rc = ssh_config_parse_uri(value, &username, &hostname, NULL, true);
|
||||||
if (rc != SSH_OK) {
|
if (rc != SSH_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (port != NULL) {
|
|
||||||
SAFE_FREE(username);
|
|
||||||
SAFE_FREE(hostname);
|
|
||||||
SAFE_FREE(port);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (username != NULL) {
|
if (username != NULL) {
|
||||||
SAFE_FREE(session->opts.username);
|
SAFE_FREE(session->opts.username);
|
||||||
session->opts.username = username;
|
session->opts.username = username;
|
||||||
|
|||||||
Reference in New Issue
Block a user