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

SSH-01-003: Add cipher NULL checks to ssh_packet_get_current_crypto()

Fixes T183

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2019-10-22 11:26:02 +02:00
parent c8a621c606
commit e60fc79542

View File

@@ -939,18 +939,38 @@ struct ssh_crypto_struct *
ssh_packet_get_current_crypto(ssh_session session,
enum ssh_crypto_direction_e direction)
{
struct ssh_crypto_struct *crypto = NULL;
if (session == NULL) {
return NULL;
}
if (session->current_crypto != NULL &&
session->current_crypto->used & direction) {
return session->current_crypto;
crypto = session->current_crypto;
} else if (session->next_crypto != NULL &&
session->next_crypto->used & direction) {
crypto = session->next_crypto;
} else {
return NULL;
}
if (session->next_crypto != NULL &&
session->next_crypto->used & direction) {
return session->next_crypto;
switch (direction) {
case SSH_DIRECTION_IN:
if (crypto->in_cipher != NULL) {
return crypto;
}
break;
case SSH_DIRECTION_OUT:
if (crypto->out_cipher != NULL) {
return crypto;
}
break;
case SSH_DIRECTION_BOTH:
if (crypto->in_cipher != NULL &&
crypto->out_cipher != NULL) {
return crypto;
}
}
return NULL;