From 239eef6322d1bca0786a60f68dab3d9b402a41b7 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 28 Apr 2020 12:27:03 +0200 Subject: [PATCH] packet: Check if set_*_key functions exists before calling it Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- src/packet.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/packet.c b/src/packet.c index c53800ea..40b60a10 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1969,23 +1969,27 @@ ssh_packet_set_newkeys(ssh_session session, session->opts.rekey_time/1000); } - /* Initialize the encryption and decryption keys in next_crypto */ - rc = in_cipher->set_decrypt_key(in_cipher, - session->next_crypto->decryptkey, - session->next_crypto->decryptIV); - if (rc < 0) { - /* On error, make sure it is not used */ - session->next_crypto->used = 0; - return SSH_ERROR; + if (in_cipher->set_decrypt_key) { + /* Initialize the encryption and decryption keys in next_crypto */ + rc = in_cipher->set_decrypt_key(in_cipher, + session->next_crypto->decryptkey, + session->next_crypto->decryptIV); + if (rc < 0) { + /* On error, make sure it is not used */ + session->next_crypto->used = 0; + return SSH_ERROR; + } } - rc = out_cipher->set_encrypt_key(out_cipher, - session->next_crypto->encryptkey, - session->next_crypto->encryptIV); - if (rc < 0) { - /* On error, make sure it is not used */ - session->next_crypto->used = 0; - return SSH_ERROR; + if (out_cipher->set_encrypt_key) { + rc = out_cipher->set_encrypt_key(out_cipher, + session->next_crypto->encryptkey, + session->next_crypto->encryptIV); + if (rc < 0) { + /* On error, make sure it is not used */ + session->next_crypto->used = 0; + return SSH_ERROR; + } } return SSH_OK;