Skip to content

Commit

Permalink
SSH2: set stream timeout before calling stream_get_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Feb 8, 2024
1 parent 498e67a commit c948a9a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion phpseclib/Net/SSH2.php
Expand Up @@ -1108,6 +1108,8 @@ class SSH2
* Default Constructor.
*
* $host can either be a string, representing the host, or a stream resource.
* If $host is a stream resource then $port doesn't do anything, altho $timeout
* still will be used
*
* @param mixed $host
* @param int $port
Expand Down Expand Up @@ -1198,6 +1200,8 @@ function __construct($host, $port = 22, $timeout = 10)
31 => 'NET_SSH2_MSG_KEX_ECDH_REPLY')
);

$this->timeout = $timeout;

if (is_resource($host)) {
$this->fsock = $host;
return;
Expand All @@ -1206,7 +1210,6 @@ function __construct($host, $port = 22, $timeout = 10)
if (is_string($host)) {
$this->host = $host;
$this->port = $port;
$this->timeout = $timeout;
}
}

Expand Down Expand Up @@ -3646,6 +3649,9 @@ function _get_binary_packet($skip_channel_filter = false)
}

$start = microtime(true);
$sec = (int) floor($this->curTimeout);
$usec = (int) (1000000 * ($this->curTimeout - $sec));
stream_set_timeout($this->fsock, $sec, $usec);
$raw = stream_get_contents($this->fsock, $this->decrypt_block_size);

if (!strlen($raw)) {
Expand Down

1 comment on commit c948a9a

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1977

Please sign in to comment.