From 96eb1f379797bca03452f2bec33315dd4d289bd4 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 5 Dec 2014 22:01:39 -0600 Subject: [PATCH] SSH2: simplify _send_channel_packet the last _send_channel_packet was unnecessarily complex. this lead to a number of problems. for example, the window size was checked for adjustments in two places. in the second place it receives a window adjustment packet and just assumes that the window adjustment packet was big enough for the rest of the data. (thanks, pixall!) --- phpseclib/Net/SSH2.php | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index c904e678..ac095110 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3275,27 +3275,23 @@ class Net_SSH2 */ function _send_channel_packet($client_channel, $data) { - /* The maximum amount of data allowed is determined by the maximum - packet size for the channel, and the current window size, whichever - is smaller. - - -- http://tools.ietf.org/html/rfc4254#section-5.2 */ - $max_size = min( - $this->packet_size_client_to_server[$client_channel], - $this->window_size_client_to_server[$client_channel] - ); - while (strlen($data) > $max_size) { + while (strlen($data)) { if (!$this->window_size_client_to_server[$client_channel]) { $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST; // using an invalid channel will let the buffers be built up for the valid channels - $output = $this->_get_channel_packet(-1); + $this->_get_channel_packet(-1); $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST; - $max_size = min( - $this->packet_size_client_to_server[$client_channel], - $this->window_size_client_to_server[$client_channel] - ); } + /* The maximum amount of data allowed is determined by the maximum + packet size for the channel, and the current window size, whichever + is smaller. + -- http://tools.ietf.org/html/rfc4254#section-5.2 */ + $max_size = min( + $this->packet_size_client_to_server[$client_channel], + $this->window_size_client_to_server[$client_channel] + ); + $temp = $this->_string_shift($data, $max_size); $packet = pack('CN2a*', NET_SSH2_MSG_CHANNEL_DATA, @@ -3303,27 +3299,13 @@ class Net_SSH2 strlen($temp), $temp ); - $this->window_size_client_to_server[$client_channel]-= strlen($temp); - if (!$this->_send_binary_packet($packet)) { return false; } } - if (strlen($data) >= $this->window_size_client_to_server[$client_channel]) { - $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST; - $this->_get_channel_packet(-1); - $this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST; - } - - $this->window_size_client_to_server[$client_channel]-= strlen($data); - - return $this->_send_binary_packet(pack('CN2a*', - NET_SSH2_MSG_CHANNEL_DATA, - $this->server_channels[$client_channel], - strlen($data), - $data)); + return true; } /**