From 52f64cdf954a525bf7de1c5f9d3be60dfbe220b5 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 11 May 2013 16:54:50 +0200 Subject: [PATCH] Fix potential NULL pointer dereferences. --- src/openssl/cipher.c | 8 +++++++- src/openssl/digest.c | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/openssl/cipher.c b/src/openssl/cipher.c index 7f73cb1..c0307f8 100644 --- a/src/openssl/cipher.c +++ b/src/openssl/cipher.c @@ -81,6 +81,9 @@ void cipher_close(cipher_t *cipher) { } size_t cipher_keylength(const cipher_t *cipher) { + if(!cipher || !cipher->cipher) + return 0; + return cipher->cipher->key_len + cipher->cipher->block_size; } @@ -221,7 +224,10 @@ bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou } int cipher_get_nid(const cipher_t *cipher) { - return cipher->cipher ? cipher->cipher->nid : 0; + if(!cipher || !cipher->cipher) + return 0; + + return cipher->cipher->nid; } bool cipher_active(const cipher_t *cipher) { diff --git a/src/openssl/digest.c b/src/openssl/digest.c index 8d97e3b..0e600b9 100644 --- a/src/openssl/digest.c +++ b/src/openssl/digest.c @@ -115,14 +115,23 @@ bool digest_verify(digest_t *digest, const void *indata, size_t inlen, const voi } int digest_get_nid(const digest_t *digest) { - return digest->digest ? digest->digest->type : 0; + if(!digest || !digest->digest) + return 0; + + return digest->digest->type; } size_t digest_keylength(const digest_t *digest) { + if(!digest || !digest->digest) + return 0; + return digest->digest->md_size; } size_t digest_length(const digest_t *digest) { + if(!digest) + return 0; + return digest->maclength; } -- 2.25.1