preference isset over array_key_exists, return false on failure, break after return channel opened

This commit is contained in:
montdidier 2015-03-24 13:38:56 +08:00
parent 1803bcac0b
commit 9723acc885
2 changed files with 7 additions and 2 deletions

View File

@ -2499,12 +2499,12 @@ class Net_SSH2
{ {
$channel = NET_SSH2_CHANNEL_EXEC; $channel = NET_SSH2_CHANNEL_EXEC;
do { 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; return $channel;
} }
} while ($channel++ < NET_SSH2_CHANNEL_SUBSYSTEM); } 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; return false;
} }
} }
break;
default: default:
$packet = pack('CN3a*Na*', $packet = pack('CN3a*Na*',
NET_SSH2_MSG_REQUEST_FAILURE, $server_channel, NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED, 0, '', 0, ''); NET_SSH2_MSG_REQUEST_FAILURE, $server_channel, NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED, 0, '', 0, '');

View File

@ -374,6 +374,10 @@ class System_SSH_Agent
function _request_forwarding($ssh) function _request_forwarding($ssh)
{ {
$request_channel = $ssh->_get_open_channel(); $request_channel = $ssh->_get_open_channel();
if ($request_channel === false) {
user_error("failed to request channel");
return false;
}
$packet = pack('CNNa*C', $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); NET_SSH2_MSG_CHANNEL_REQUEST, $ssh->server_channels[$request_channel], strlen('auth-agent-req@openssh.com'), 'auth-agent-req@openssh.com', 1);