mirror of
https://github.com/php/pecl-networking-ssh2.git
synced 2026-03-23 22:52:06 +01:00
Fix #79631: SSH disconnect segfault with SFTP (assertion failed)
If the SSH2 Session resource has already been closed, the libssh2 session has been as well, and the `LIBSSH2_SESSION*` has been set NULL. If that is the case, we must not call `libssh2_sftp_shutdown()`.
This commit is contained in:
@@ -36,7 +36,9 @@ void php_ssh2_sftp_dtor(zend_resource *rsrc)
|
||||
return;
|
||||
}
|
||||
|
||||
libssh2_sftp_shutdown(data->sftp);
|
||||
if (data->session_rsrc->ptr != NULL) {
|
||||
libssh2_sftp_shutdown(data->sftp);
|
||||
}
|
||||
|
||||
zend_list_delete(data->session_rsrc);
|
||||
|
||||
@@ -873,6 +875,10 @@ PHP_FUNCTION(ssh2_sftp_realpath)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (data->session_rsrc->ptr == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if ((targ_len = libssh2_sftp_symlink_ex(data->sftp, link->val, link->len, targ, 8192, LIBSSH2_SFTP_REALPATH)) < 0) {
|
||||
php_error_docref(NULL, E_WARNING, "Unable to resolve realpath for '%s'", link->val);
|
||||
RETURN_FALSE;
|
||||
|
||||
20
tests/bug79631.phpt
Normal file
20
tests/bug79631.phpt
Normal file
@@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
Bug 79631 (SSH disconnect segfault with SFTP (assertion failed))
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require('ssh2_skip.inc');
|
||||
ssh2t_needs_auth();
|
||||
ssh2t_writes_remote();
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('ssh2_test.inc');
|
||||
|
||||
$ssh = ssh2_connect(TEST_SSH2_HOSTNAME, TEST_SSH2_PORT);
|
||||
ssh2t_auth($ssh);
|
||||
$sftp = ssh2_sftp($ssh);
|
||||
ssh2_disconnect($ssh);
|
||||
echo "done\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
done
|
||||
Reference in New Issue
Block a user