]> git.meshlink.io Git - meshlink/commitdiff
Fix potential NULL pointer dereferences.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 11 May 2013 14:54:50 +0000 (16:54 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 11 May 2013 14:54:50 +0000 (16:54 +0200)
src/openssl/cipher.c
src/openssl/digest.c

index 7f73cb1bbc22e53f7b34025521783986e2b190d7..c0307f8231b5f81b094dddd61277d9e1f07669ec 100644 (file)
@@ -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) {
index 8d97e3bf9ed345c53e5db8dc7949297e06920c65..0e600b9d07d31a0e83bfcecab08809442fbd467d 100644 (file)
@@ -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;
 }