From 9723acc8853c5fe7ea9bda4a9a711a3e07575c84 Mon Sep 17 00:00:00 2001 From: montdidier Date: Tue, 24 Mar 2015 13:38:56 +0800 Subject: [PATCH] preference isset over array_key_exists, return false on failure, break after return channel opened --- phpseclib/Net/SSH2.php | 5 +++-- phpseclib/System/SSH/Agent.php | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 6dd7dc1c..4f55eb64 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2499,12 +2499,12 @@ class Net_SSH2 { $channel = NET_SSH2_CHANNEL_EXEC; do { - if (array_key_exists($channel, $this->channel_status) && $this->channel_status[$channel] == NET_SSH2_MSG_CHANNEL_OPEN) { + if (isset($this->channel_status[$channel]) && $this->channel_status[$channel] == NET_SSH2_MSG_CHANNEL_OPEN) { return $channel; } } while ($channel++ < NET_SSH2_CHANNEL_SUBSYSTEM); - user_error("Unable to find an open channel"); + return false; } /** @@ -2891,6 +2891,7 @@ class Net_SSH2 return false; } } + break; default: $packet = pack('CN3a*Na*', NET_SSH2_MSG_REQUEST_FAILURE, $server_channel, NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED, 0, '', 0, ''); diff --git a/phpseclib/System/SSH/Agent.php b/phpseclib/System/SSH/Agent.php index ccdfce02..86ca18ac 100644 --- a/phpseclib/System/SSH/Agent.php +++ b/phpseclib/System/SSH/Agent.php @@ -374,6 +374,10 @@ class System_SSH_Agent function _request_forwarding($ssh) { $request_channel = $ssh->_get_open_channel(); + if ($request_channel === false) { + user_error("failed to request channel"); + return false; + } $packet = pack('CNNa*C', NET_SSH2_MSG_CHANNEL_REQUEST, $ssh->server_channels[$request_channel], strlen('auth-agent-req@openssh.com'), 'auth-agent-req@openssh.com', 1);