From 28211e5a49cccff974330d738d71cb8e55504ae9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 17 May 2024 16:58:11 -0500 Subject: [PATCH 1/2] SFTP: try without path canonicalization if initial realpath() fails on re-examining the "fix" for #1796 it would appear that commit f189b9a is insufficient. --- phpseclib/Net/SFTP.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 451a2cbd..55d63f0b 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -813,7 +813,8 @@ class Net_SFTP extends Net_SSH2 return false; } $this->canonicalize_paths = false; - $this->_reset_connection(NET_SSH2_DISCONNECT_CONNECTION_LOST); + $this->_reset_sftp(); + return $this->_init_sftp_connection(); } $this->_update_stat_cache($this->pwd, array()); @@ -3683,6 +3684,19 @@ class Net_SFTP extends Net_SSH2 return $result; } + /** + * Resets the SFTP channel for re-use + * + * @access private + */ + function _reset_sftp() + { + $this->use_request_id = false; + $this->pwd = false; + $this->requestBuffer = []; + $this->partial_init = false; + } + /** * Resets a connection for re-use * @@ -3692,10 +3706,7 @@ class Net_SFTP extends Net_SSH2 function _reset_connection($reason) { parent::_reset_connection($reason); - $this->use_request_id = false; - $this->pwd = false; - $this->requestBuffer = array(); - $this->partial_init = false; + $this->_reset_sftp(); } /** From 023f5c00be04c1af7feeffbba75f3c24976ab7a0 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 17 May 2024 18:40:42 -0500 Subject: [PATCH 2/2] CS adjustment --- phpseclib/Net/SFTP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 55d63f0b..610a6559 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -3693,7 +3693,7 @@ class Net_SFTP extends Net_SSH2 { $this->use_request_id = false; $this->pwd = false; - $this->requestBuffer = []; + $this->requestBuffer = array(); $this->partial_init = false; }