From f664ccb521819c075f727ffa9953cb4e7050e2e9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 7 May 2023 11:07:07 -0500 Subject: [PATCH] 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(); }