mirror of
https://github.com/curl/curl.git
synced 2026-08-01 20:10:29 +03:00
sftp: fix segfault regression introduced by #4747
This fix adds a defensive check for the case where the char *name in struct libssh2_knownhost is NULL Fixes #5041 Closes #5062
This commit is contained in:
parent
464d944b51
commit
e96fe70cab
3 changed files with 72 additions and 17 deletions
|
|
@ -694,31 +694,40 @@ static CURLcode ssh_force_knownhost_key_type(struct connectdata *conn)
|
|||
while(!libssh2_knownhost_get(sshc->kh, &store, store)) {
|
||||
/* For non-standard ports, the name will be enclosed in */
|
||||
/* square brackets, followed by a colon and the port */
|
||||
if(store->name[0] == '[') {
|
||||
kh_name_end = strstr(store->name, "]:");
|
||||
if(!kh_name_end) {
|
||||
infof(data, "Invalid host pattern %s in %s\n",
|
||||
store->name, data->set.str[STRING_SSH_KNOWNHOSTS]);
|
||||
continue;
|
||||
}
|
||||
port = atoi(kh_name_end + 2);
|
||||
if(kh_name_end && (port == conn->remote_port)) {
|
||||
kh_name_size = strlen(store->name) - 1 - strlen(kh_name_end);
|
||||
if(strncmp(store->name + 1, conn->host.name, kh_name_size) == 0) {
|
||||
if(store) {
|
||||
if(store->name) {
|
||||
if(store->name[0] == '[') {
|
||||
kh_name_end = strstr(store->name, "]:");
|
||||
if(!kh_name_end) {
|
||||
infof(data, "Invalid host pattern %s in %s\n",
|
||||
store->name, data->set.str[STRING_SSH_KNOWNHOSTS]);
|
||||
continue;
|
||||
}
|
||||
port = atoi(kh_name_end + 2);
|
||||
if(kh_name_end && (port == conn->remote_port)) {
|
||||
kh_name_size = strlen(store->name) - 1 - strlen(kh_name_end);
|
||||
if(strncmp(store->name + 1,
|
||||
conn->host.name, kh_name_size) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(store->name, conn->host.name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strcmp(store->name, conn->host.name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
else {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(found) {
|
||||
infof(data, "Found host %s in %s\n",
|
||||
store->name, data->set.str[STRING_SSH_KNOWNHOSTS]);
|
||||
conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]);
|
||||
|
||||
switch(store->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) {
|
||||
#ifdef LIBSSH2_KNOWNHOST_KEY_ED25519
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue