Fix: NULL pointer check in ssh_channel_is_closed

The ssh_channel_is_closed function would crash when
accessing channel->session->alive if session is NULL.
This patch adds a null check before accessing the session
pointer.

- build succeeded
- unit test passed
- no new unit test added

https://gitlab.com/libssh/libssh-mirror/-/issues/239

Signed-off-by: Raviraaja Lakshmanan <mailstoraviraaja@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
RaviRaaja
2025-04-08 16:00:41 +05:30
committed by Jakub Jelen
parent b106211d92
commit 04a58919f8

View File

@@ -1728,7 +1728,7 @@ int ssh_channel_is_open(ssh_channel channel)
*/
int ssh_channel_is_closed(ssh_channel channel)
{
if (channel == NULL) {
if (channel == NULL || channel->session == NULL) {
return SSH_ERROR;
}
return (channel->state != SSH_CHANNEL_STATE_OPEN || channel->session->alive == 0);