[PECL-CVS] [pecl-networking-ssh2] master: Fix call to ssh2_auth_pubkey() without password

[email protected] (Christian Weiske via Casper Langemeijer)
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Christian Weiske (cweiske)
Committer: Casper Langemeijer (langemeijer)
Date: 2025-11-23T12:25:11+01:00

Commit: https://github.com/php/pecl-networking-ssh2/commit/a0621be8524c007dfba901073006c5c4d94c6fe5
Raw diff: https://github.com/php/pecl-networking-ssh2/commit/a0621be8524c007dfba901073006c5c4d94c6fe5.diff

Fix call to ssh2_auth_pubkey() without password

Port of the previous fix for ssh2_auth_pubkey_file() to
the passwordless function introduced after that patch.

Related: https://bugs.php.net/bug.php?id=79702

Changed paths:
  M  ssh2.c


Diff:

diff --git a/ssh2.c b/ssh2.c
index e831967..bc21083 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -709,7 +709,7 @@ PHP_FUNCTION(ssh2_auth_pubkey)
 {
 	LIBSSH2_SESSION *session;
 	zval *zsession;
-	zend_string *username, *pubkey, *privkey, *passphrase;
+	zend_string *username, *pubkey, *privkey, *passphrase = NULL;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSSS|S", &zsession,	&username, &pubkey, &privkey, &passphrase) == FAILURE) {
 		return;
@@ -717,7 +717,7 @@ PHP_FUNCTION(ssh2_auth_pubkey)
 
 	SSH2_FETCH_NONAUTHENTICATED_SESSION(session, zsession);
 
-	if (libssh2_userauth_publickey_frommemory(session, ZSTR_VAL(username), ZSTR_LEN(username), ZSTR_VAL(pubkey), ZSTR_LEN(pubkey), ZSTR_VAL(privkey), ZSTR_LEN(privkey), ZSTR_VAL(passphrase))) {
+	if (libssh2_userauth_publickey_frommemory(session, ZSTR_VAL(username), ZSTR_LEN(username), ZSTR_VAL(pubkey), ZSTR_LEN(pubkey), ZSTR_VAL(privkey), ZSTR_LEN(privkey), passphrase ? ZSTR_VAL(passphrase) : NULL)) {
 		char *buf;
 		int len;
 		libssh2_session_last_error(session, &buf, &len, 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.