mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-27 13:21:11 +03:00
CVE-2023-6004: options: Simplify the hostname parsing in ssh_options_set
Using ssh_config_parse_uri can simplify the parsing of the host parsing inside the function of ssh_options_set Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Andreas Schneider
parent
1dfde16f49
commit
b83368b2ed
@@ -37,6 +37,7 @@
|
|||||||
#include "libssh/session.h"
|
#include "libssh/session.h"
|
||||||
#include "libssh/misc.h"
|
#include "libssh/misc.h"
|
||||||
#include "libssh/options.h"
|
#include "libssh/options.h"
|
||||||
|
#include "libssh/config_parser.h"
|
||||||
#ifdef WITH_SERVER
|
#ifdef WITH_SERVER
|
||||||
#include "libssh/server.h"
|
#include "libssh/server.h"
|
||||||
#include "libssh/bind.h"
|
#include "libssh/bind.h"
|
||||||
@@ -633,33 +634,24 @@ 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 {
|
||||||
q = strdup(value);
|
char *username = NULL, *hostname = NULL, *port = NULL;
|
||||||
if (q == NULL) {
|
rc = ssh_config_parse_uri(value, &username, &hostname, &port);
|
||||||
ssh_set_error_oom(session);
|
if (rc != SSH_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
p = strrchr(q, '@');
|
if (port != NULL) {
|
||||||
|
SAFE_FREE(username);
|
||||||
SAFE_FREE(session->opts.host);
|
SAFE_FREE(hostname);
|
||||||
|
SAFE_FREE(port);
|
||||||
if (p) {
|
return -1;
|
||||||
*p = '\0';
|
}
|
||||||
session->opts.host = strdup(p + 1);
|
if (username != NULL) {
|
||||||
if (session->opts.host == NULL) {
|
|
||||||
SAFE_FREE(q);
|
|
||||||
ssh_set_error_oom(session);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_FREE(session->opts.username);
|
SAFE_FREE(session->opts.username);
|
||||||
session->opts.username = strdup(q);
|
session->opts.username = username;
|
||||||
SAFE_FREE(q);
|
}
|
||||||
if (session->opts.username == NULL) {
|
if (hostname != NULL) {
|
||||||
ssh_set_error_oom(session);
|
SAFE_FREE(session->opts.host);
|
||||||
return -1;
|
session->opts.host = hostname;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
session->opts.host = q;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user