From e60fc79542db5776a18e2dd4dff23b05c87b259a Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 22 Oct 2019 11:26:02 +0200 Subject: [PATCH] SSH-01-003: Add cipher NULL checks to ssh_packet_get_current_crypto() Fixes T183 Signed-off-by: Andreas Schneider Reviewed-by: Jakub Jelen --- src/packet.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/packet.c b/src/packet.c index dc844830..80e2a982 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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;