channels: Avoid out-of-bounds writes

CID 1470005

Thanks coverity

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Norbert Pocs <npocs@redhat.com>
This commit is contained in:
Jakub Jelen
2023-06-28 12:14:43 +02:00
parent ebea7d9023
commit 9c19ba7f33

View File

@@ -3584,9 +3584,15 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans,
firstround=0;
} while(1);
memcpy(readchans, rchans, (count_ptrs(rchans) + 1) * sizeof(ssh_channel ));
memcpy(writechans, wchans, (count_ptrs(wchans) + 1) * sizeof(ssh_channel ));
memcpy(exceptchans, echans, (count_ptrs(echans) + 1) * sizeof(ssh_channel ));
if (readchans != &dummy) {
memcpy(readchans, rchans, (count_ptrs(rchans) + 1) * sizeof(ssh_channel));
}
if (writechans != &dummy) {
memcpy(writechans, wchans, (count_ptrs(wchans) + 1) * sizeof(ssh_channel));
}
if (exceptchans != &dummy) {
memcpy(exceptchans, echans, (count_ptrs(echans) + 1) * sizeof(ssh_channel));
}
SAFE_FREE(rchans);
SAFE_FREE(wchans);
SAFE_FREE(echans);