1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-26 01:03:15 +03:00

channels: Refactor channel_rcv_data, check for errors and report more useful errors

CID 1513157

Thanks coverity

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
Jakub Jelen
2023-06-20 14:54:50 +02:00
parent a45b9938fe
commit 4b8db203b0

View File

@@ -563,15 +563,15 @@ SSH_PACKET_CALLBACK(channel_rcv_data)
ssh_buffer buf = NULL; ssh_buffer buf = NULL;
void *data = NULL; void *data = NULL;
uint32_t len; uint32_t len;
int is_stderr; int extended, is_stderr = 0;
int rest; int rest;
(void)user; (void)user;
if (type == SSH2_MSG_CHANNEL_DATA) { if (type == SSH2_MSG_CHANNEL_DATA) {
is_stderr = 0; extended = 0;
} else { } else { /* SSH_MSG_CHANNEL_EXTENDED_DATA */
is_stderr = 1; extended = 1;
} }
channel = channel_from_msg(session, packet); channel = channel_from_msg(session, packet);
@@ -581,10 +581,21 @@ SSH_PACKET_CALLBACK(channel_rcv_data)
return SSH_PACKET_USED; return SSH_PACKET_USED;
} }
if (is_stderr) { if (extended) {
uint32_t ignore; uint32_t data_type_code, rc;
/* uint32 data type code. we can ignore it */ rc = ssh_buffer_get_u32(packet, &data_type_code);
ssh_buffer_get_u32(packet, &ignore); if (rc != sizeof(uint32_t)) {
SSH_LOG(SSH_LOG_PACKET,
"Failed to read data type code: rc = %" PRIu32, rc);
return SSH_PACKET_USED;
}
if (data_type_code == 1) {
is_stderr = 1;
} else {
SSH_LOG(SSH_LOG_PACKET, "Invalid data type code %" PRIu32 "!",
data_type_code);
}
} }
str = ssh_buffer_get_ssh_string(packet); str = ssh_buffer_get_ssh_string(packet);
@@ -596,10 +607,10 @@ SSH_PACKET_CALLBACK(channel_rcv_data)
len = ssh_string_len(str); len = ssh_string_len(str);
SSH_LOG(SSH_LOG_PACKET, SSH_LOG(SSH_LOG_PACKET,
"Channel receiving %" PRIu32 " bytes data in %d (local win=%" PRIu32 "Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
" remote win=%" PRIu32 ")", " remote win=%" PRIu32 ")",
len, len,
is_stderr, is_stderr ? " in stderr" : "",
channel->local_window, channel->local_window,
channel->remote_window); channel->remote_window);