From f664ccb521819c075f727ffa9953cb4e7050e2e9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 7 May 2023 11:07:07 -0500 Subject: [PATCH 1/3] SSH2: make exceptions more useful for read() / write() --- phpseclib/Net/SSH2.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 0dd3a2ee..fa3ed4d6 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3063,6 +3063,10 @@ class SSH2 */ public function read($expect = '', $mode = self::READ_SIMPLE, $channel = null) { + if (!$this->isAuthenticated()) { + throw new InsufficientSetupException('Operation disallowed prior to login()'); + } + $this->curTimeout = $this->timeout; $this->is_timeout = false; @@ -3120,6 +3124,10 @@ class SSH2 */ public function write($cmd, $channel = null) { + if (!$this->isAuthenticated()) { + throw new InsufficientSetupException('Operation disallowed prior to login()'); + } + if ($channel === null) { $channel = $this->get_interactive_channel(); } From 89d8e6ecbbd5a2ae1b55a610280bf1127c8dd472 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 7 May 2023 11:07:38 -0500 Subject: [PATCH 2/3] SFTP: rm redundant code --- phpseclib/Net/SFTP.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 7015d904..3d190ada 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -545,8 +545,6 @@ class SFTP extends SSH2 */ private function partial_init_sftp_connection() { - $this->window_size_server_to_client[self::CHANNEL] = $this->window_size; - $response = $this->openChannel(self::CHANNEL, true); if ($response === true && $this->isTimeout()) { return false; From 3dd777993949f5e9467c0d48bc0338effa63ca08 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 7 May 2023 11:24:33 -0500 Subject: [PATCH 3/3] SSH2: rm redundant isAuthenticated() call --- phpseclib/Net/SSH2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index fa3ed4d6..ac6bf3b9 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3074,7 +3074,7 @@ class SSH2 $channel = $this->get_interactive_channel(); } - if (!$this->isInteractiveChannelOpen($channel) && empty($this->channel_buffers[$channel])) { + if (!$this->is_channel_status_data($channel) && empty($this->channel_buffers[$channel])) { if ($channel != self::CHANNEL_SHELL) { throw new InsufficientSetupException('Data is not available on channel'); } elseif (!$this->openShell()) { @@ -3132,7 +3132,7 @@ class SSH2 $channel = $this->get_interactive_channel(); } - if (!$this->isInteractiveChannelOpen($channel)) { + if (!$this->is_channel_status_data($channel)) { if ($channel != self::CHANNEL_SHELL) { throw new InsufficientSetupException('Data is not available on channel'); } elseif (!$this->openShell()) {