php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #68023
Patch ssh2-auth-none-segfault-fix revision 2014-09-16 00:41 UTC by felipe at weckx dot net

Patch ssh2-auth-none-segfault-fix for ssh2 Bug #68023

Patch version 2014-09-16 00:41 UTC

Return to Bug #68023 | Download this patch
Patch Revisions:

Developer: felipe@weckx.net

From 8a0925f6ee4eaf6f6aa1c0356f658bcb0320342b Mon Sep 17 00:00:00 2001
From: Felipe Weckx <felipe@weckx.net>
Date: Mon, 15 Sep 2014 21:12:02 -0300
Subject: [PATCH] Fix segfault when trying to authenticate in servers that do
 not support authentication (none)

---
 ssh2.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/ssh2.c b/ssh2.c
index f232c41..bb6bef2 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -636,17 +636,20 @@ PHP_FUNCTION(ssh2_auth_password)
 	SSH2_FETCH_NONAUTHENTICATED_SESSION(session, zsession);
 
 	userauthlist = libssh2_userauth_list(session, username, username_len);
-	password_for_kbd_callback = password;
-	if (strstr(userauthlist, "keyboard-interactive") != NULL) {
-		if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) == 0) {
-			RETURN_TRUE;
+
+	if (userauthlist != NULL) {
+		password_for_kbd_callback = password;
+		if (strstr(userauthlist, "keyboard-interactive") != NULL) {
+			if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) == 0) {
+				RETURN_TRUE;
+			}
 		}
-	}
 
-	/* TODO: Support password change callback */
-	if (libssh2_userauth_password_ex(session, username, username_len, password, password_len, NULL)) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username);
-		RETURN_FALSE;
+		/* TODO: Support password change callback */
+		if (libssh2_userauth_password_ex(session, username, username_len, password, password_len, NULL)) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username);
+			RETURN_FALSE;
+		}
 	}
 
 	RETURN_TRUE;
@@ -1167,7 +1170,7 @@ PHP_FUNCTION(ssh2_auth_agent)
 	/* check what authentication methods are available */
 	userauthlist = libssh2_userauth_list(session, username, username_len);
 
-	if (strstr(userauthlist, "publickey") == NULL) {
+	if (userauthlist != NULL && strstr(userauthlist, "publickey") == NULL) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "\"publickey\" authentication is not supported");
 		RETURN_FALSE;
 	}
-- 
2.1.0

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC