SSH2: make sendEOF() better handle different channel situations

This commit is contained in:
terrafrost 2025-01-15 23:48:41 -06:00
parent 373586f8cc
commit 087fe31caf
2 changed files with 25 additions and 4 deletions

View File

@ -3346,7 +3346,8 @@ class SSH2
}
}
/** Send EOF on a channel
/**
* Send EOF on a channel
*
* Sends an EOF to the stream; this is typically used to close standard
* input, while keeping output and error alive.
@ -3360,7 +3361,10 @@ class SSH2
$channel = $this->get_interactive_channel();
}
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$channel]));
$excludeStatuses = [NET_SSH2_MSG_CHANNEL_EOF, NET_SSH2_MSG_CHANNEL_CLOSE];
if (isset($this->channel_status[$channel]) && !in_array($this->channel_status[$channel], $excludeStatuses)) {
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$channel]));
}
}
/**
@ -4201,7 +4205,9 @@ class SSH2
}
if (isset($this->channel_status[$channel]) && $this->channel_status[$channel] != NET_SSH2_MSG_CHANNEL_CLOSE) {
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$channel]));
if ($this->channel_status[$channel] != NET_SSH2_MSG_CHANNEL_EOF) {
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$channel]));
}
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$channel]));
$this->channel_status[$channel] = NET_SSH2_MSG_CHANNEL_CLOSE;
@ -4679,7 +4685,9 @@ class SSH2
{
// see http://tools.ietf.org/html/rfc4254#section-5.3
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel]));
if ($this->channel_status[$client_channel] != NET_SSH2_MSG_CHANNEL_EOF) {
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_EOF, $this->server_channels[$client_channel]));
}
$this->send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
$this->channel_status[$client_channel] = NET_SSH2_MSG_CHANNEL_CLOSE;

View File

@ -617,6 +617,19 @@ class SSH2Test extends PhpseclibFunctionalTestCase
return $tests;
}
/**
* @group github2062
*/
public function testSendEOF()
{
$ssh = $this->getSSH2Login();
$ssh->write("ls -latr; exit\n");
$ssh->read();
$ssh->sendEOF();
$ssh->exec('ls -latr');
}
/**
* @dataProvider getCryptoAlgorithms
* @param string $type