Skip to content

Commit be538e0

Browse files
committed
ssh: make CURLOPT_SSH_PUBLIC_KEYFILE treat "" as NULL
The CURLOPT_SSH_PUBLIC_KEYFILE option has been documented to handle empty strings specially since curl-7_25_0-31-g05a443a but the behavior was unintentionally removed in curl-7_38_0-47-gfa7d04f. This commit restores the original behavior and clarifies it in the documentation that NULL and "" have both the same meaning when passed to CURLOPT_SSH_PUBLIC_KEYFILE. Bug: http://curl.haxx.se/mail/lib-2016-01/0072.html
1 parent be79d83 commit be538e0

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

RELEASE-NOTES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ This release includes the following bugfixes:
6868
o configure: assume IPv6 works when cross-compiled [29]
6969
o openssl: for 1.1.0+ they now provide a SSLeay() macro of their own
7070
o openssl: improved error detection/reporting
71+
o ssh: CURLOPT_SSH_PUBLIC_KEYFILE now treats "" as NULL again [30]
7172

7273
This release includes the following known bugs:
7374

@@ -116,4 +117,5 @@ References to bug reports and discussions on issues:
116117
[27] = http://curl.haxx.se/bug/?i=597
117118
[28] = http://curl.haxx.se/bug/?i=584
118119
[29] = http://curl.haxx.se/bug/?i=594
120+
[30] = http://curl.haxx.se/mail/lib-2016-01/0072.html
119121

docs/libcurl/opts/CURLOPT_SSH_PUBLIC_KEYFILE.3

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ libcurl defaults to \fB$HOME/.ssh/id_dsa.pub\fP if the HOME environment
3535
variable is set, and just "id_dsa.pub" in the current directory if HOME is not
3636
set.
3737

38-
If an empty string is passed, libcurl will pass no public key to libssh2 which
39-
then tries to compute it from the private key, this is known to work when
40-
libssh2 1.4.0+ is linked against OpenSSL.
38+
If NULL (or an empty string) is passed, libcurl will pass no public key to
39+
libssh2, which then tries to compute it from the private key. This is known
40+
to work with libssh2 1.4.0+ linked against OpenSSL.
4141
.SH DEFAULT
42-
As explained above
42+
NULL
4343
.SH PROTOCOLS
4444
SFTP and SCP
4545
.SH EXAMPLE

lib/ssh.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
848848
* libssh2 extract the public key from the private key file.
849849
* This is done by simply passing sshc->rsa_pub = NULL.
850850
*/
851-
if(data->set.str[STRING_SSH_PUBLIC_KEY]) {
851+
if(data->set.str[STRING_SSH_PUBLIC_KEY]
852+
/* treat empty string the same way as NULL */
853+
&& data->set.str[STRING_SSH_PUBLIC_KEY][0]) {
852854
sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]);
853855
if(!sshc->rsa_pub)
854856
out_of_memory = TRUE;
@@ -869,7 +871,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
869871

870872
free(home);
871873

872-
infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
874+
if(sshc->rsa_pub)
875+
infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
873876
infof(data, "Using SSH private key file '%s'\n", sshc->rsa);
874877

875878
state(conn, SSH_AUTH_PKEY);

0 commit comments

Comments
 (0)