From fe4dc433cc66b2fe854cd8fd50c04079995d2c22 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 11 Nov 2021 19:06:18 -0600 Subject: [PATCH 1/2] SSH2: error out when no data is received from the server --- phpseclib/Net/SSH2.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index a95a3fd8..89e57487 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3537,7 +3537,8 @@ class Net_SSH2 $raw = fread($this->fsock, $this->decrypt_block_size); if (!strlen($raw)) { - return ''; + user_error('No data received from server'); + return false; } if ($this->decrypt !== false) { From 779e11e4963c52bc9fa690c370ce7f528053b99a Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 11 Nov 2021 19:39:49 -0600 Subject: [PATCH 2/2] SSH2: use exceptions rather than user_error --- 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 89c6b3df..2162b9c7 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3335,8 +3335,8 @@ class SSH2 $raw = stream_get_contents($this->fsock, $this->decrypt_block_size); if (!strlen($raw)) { - user_error('No data received from server'); - return false; + $this->bitmap = 0; + throw new ConnectionClosedException('No data received from server'); } if ($this->decrypt) {