Skip to content

Commit 7428060

Browse files
committed
libssh2: cleanup ssh_force_knownhost_key_type
- Use arrays instead pointers - Narrow variable scopes Closes curl#19479
1 parent 7aaf9a3 commit 7428060

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

lib/vssh/libssh2.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -727,38 +727,30 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data,
727727
{
728728
CURLcode result = CURLE_OK;
729729

730-
static const char * const hostkey_method_ssh_ed25519
731-
= "ssh-ed25519";
732-
static const char * const hostkey_method_ssh_ecdsa_521
733-
= "ecdsa-sha2-nistp521";
734-
static const char * const hostkey_method_ssh_ecdsa_384
735-
= "ecdsa-sha2-nistp384";
736-
static const char * const hostkey_method_ssh_ecdsa_256
737-
= "ecdsa-sha2-nistp256";
738-
static const char * const hostkey_method_ssh_rsa_all
739-
= "rsa-sha2-256,rsa-sha2-512,ssh-rsa";
740-
static const char * const hostkey_method_ssh_dss
741-
= "ssh-dss";
742-
743-
const char *hostkey_method = NULL;
744-
struct connectdata *conn = data->conn;
745-
struct libssh2_knownhost* store = NULL;
746-
const char *kh_name_end = NULL;
747-
size_t kh_name_size = 0;
748-
int port = 0;
730+
static const char hostkey_method_ssh_ed25519[] = "ssh-ed25519";
731+
static const char hostkey_method_ssh_ecdsa_521[] = "ecdsa-sha2-nistp521";
732+
static const char hostkey_method_ssh_ecdsa_384[] = "ecdsa-sha2-nistp384";
733+
static const char hostkey_method_ssh_ecdsa_256[] = "ecdsa-sha2-nistp256";
734+
static const char hostkey_method_ssh_rsa_all[] =
735+
"rsa-sha2-256,rsa-sha2-512,ssh-rsa";
736+
static const char hostkey_method_ssh_dss[] = "ssh-dss";
749737
bool found = FALSE;
750738

751739
if(sshc->kh &&
752740
!data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5] &&
753741
!data->set.str[STRING_SSH_HOST_PUBLIC_KEY_SHA256]) {
742+
struct libssh2_knownhost *store = NULL;
743+
struct connectdata *conn = data->conn;
754744
/* lets try to find our host in the known hosts file */
755745
while(!libssh2_knownhost_get(sshc->kh, &store, store)) {
756746
/* For non-standard ports, the name will be enclosed in */
757747
/* square brackets, followed by a colon and the port */
758748
if(store) {
759749
if(store->name) {
760750
if(store->name[0] == '[') {
761-
kh_name_end = strstr(store->name, "]:");
751+
int port = 0;
752+
size_t kh_name_size = 0;
753+
const char *kh_name_end = strstr(store->name, "]:");
762754
if(!kh_name_end) {
763755
infof(data, "Invalid host pattern %s in %s",
764756
store->name, data->set.str[STRING_SSH_KNOWNHOSTS]);
@@ -788,6 +780,7 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data,
788780

789781
if(found) {
790782
int rc;
783+
const char *hostkey_method = NULL;
791784
infof(data, "Found host %s in %s",
792785
conn->host.name, data->set.str[STRING_SSH_KNOWNHOSTS]);
793786

0 commit comments

Comments
 (0)