Commit 2629fc874da258d76a63a99566a5ba457c9d5d30

Michał Górny 2015-05-24T22:33:55

cred: Check for null values when getting key from memory The public key field is optional and as such can take NULL. Account for that and do not call strlen() on NULL values. Also assert() for non-NULL values of username & private key.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 0a74227..58f1aeb 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -374,12 +374,15 @@ static int _git_ssh_authenticate_session(
 		case GIT_CREDTYPE_SSH_MEMORY: {
 			git_cred_ssh_key *c = (git_cred_ssh_key *)cred;
 
+			assert(c->username);
+			assert(c->privatekey);
+
 			rc = libssh2_userauth_publickey_frommemory(
 				session,
 				c->username,
 				strlen(c->username),
 				c->publickey,
-				strlen(c->publickey),
+				c->publickey ? strlen(c->publickey) : 0,
 				c->privatekey,
 				strlen(c->privatekey),
 				c->passphrase);