Skip to content

Commit b2e0b4d

Browse files
committed
libssh2: replace atoi() in ssh_force_knownhost_key_type
Closes curl#19479
1 parent 7428060 commit b2e0b4d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lib/vssh/libssh2.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,19 +748,21 @@ static CURLcode ssh_force_knownhost_key_type(struct Curl_easy *data,
748748
if(store) {
749749
if(store->name) {
750750
if(store->name[0] == '[') {
751-
int port = 0;
751+
curl_off_t port;
752752
size_t kh_name_size = 0;
753+
const char *p;
753754
const char *kh_name_end = strstr(store->name, "]:");
754755
if(!kh_name_end) {
755756
infof(data, "Invalid host pattern %s in %s",
756757
store->name, data->set.str[STRING_SSH_KNOWNHOSTS]);
757758
continue;
758759
}
759-
port = atoi(kh_name_end + 2);
760-
if(kh_name_end && (port == conn->remote_port)) {
760+
p = kh_name_end + 2; /* start of port number */
761+
if(!curlx_str_number(&p, &port, 0xffff) &&
762+
(kh_name_end && (port == conn->remote_port))) {
761763
kh_name_size = strlen(store->name) - 1 - strlen(kh_name_end);
762764
if(strncmp(store->name + 1,
763-
conn->host.name, kh_name_size) == 0) {
765+
conn->host.name, kh_name_size) == 0) {
764766
found = TRUE;
765767
break;
766768
}

0 commit comments

Comments
 (0)