changeset 20397:4852054b2ba4

lib-dcrypt: Assert-crash if key parameter is NULL. If it happens, it's a bug.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 19 Jun 2016 20:55:19 +0300
parents 44c7e5e1432c
children cf3bb56f9ce9
files src/lib-dcrypt/dcrypt-openssl.c
diffstat 1 files changed, 5 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/dcrypt-openssl.c	Sun Jun 19 20:48:27 2016 +0300
+++ b/src/lib-dcrypt/dcrypt-openssl.c	Sun Jun 19 20:55:19 2016 +0300
@@ -1658,11 +1658,7 @@
 	char *encryption_key_hash = NULL;
 	char *key_hash = NULL;
 
-	if (key_data == NULL) {
-		if (error_r != NULL)
-			*error_r = "NULL key passed";
-		return FALSE;
-	}
+	i_assert(key_data != NULL);
 
 	/* is it PEM key */
 	if (strncmp(key_data, "-----BEGIN ", 11) == 0) {
@@ -1888,11 +1884,7 @@
 	unsigned char buf[SHA256_DIGEST_LENGTH];
 	EVP_PKEY *pub = (EVP_PKEY*)key;
 
-	if (pub == NULL) {
-		if (error_r != NULL)
-			*error_r = "key is NULL";
-		return FALSE;
-	}
+	i_assert(pub != NULL);
 	if (EVP_PKEY_base_id(pub) != EVP_PKEY_EC) {
 		if (error_r != NULL)
 			*error_r = "Only EC key supported";
@@ -1913,11 +1905,7 @@
 	unsigned char buf[SHA256_DIGEST_LENGTH];
 	EVP_PKEY *priv = (EVP_PKEY*)key;
 
-	if (priv == NULL) {
-		if (error_r != NULL)
-			*error_r = "key is NULL";
-		return FALSE;
-	}
+	i_assert(priv != NULL);
 	if (EVP_PKEY_base_id(priv) != EVP_PKEY_EC) {
 		if (error_r != NULL)
 			*error_r = "Only EC key supported";
@@ -1979,16 +1967,12 @@
 	const EVP_MD *md = EVP_get_digestbyname(algorithm);
 	EVP_PKEY *pub = (EVP_PKEY*)key;
 
+	i_assert(pub != NULL);
 	if (md == NULL) {
 		if (error_r != NULL)
 			*error_r = t_strdup_printf("Unknown cipher %s", algorithm);
 		return FALSE;
 	}
-	if (pub == NULL) {
-		if (error_r != NULL)
-			*error_r = "key is NULL";
-		return FALSE;
-	}
 
 	return dcrypt_openssl_public_key_id_evp(pub, md, result, error_r);
 }
@@ -1999,16 +1983,12 @@
 	const EVP_MD *md = EVP_get_digestbyname(algorithm);
 	EVP_PKEY *priv = (EVP_PKEY*)key;
 
+	i_assert(priv != NULL);
 	if (md == NULL) {
 		if (error_r != NULL)
 			*error_r = t_strdup_printf("Unknown cipher %s", algorithm);
 		return FALSE;
 	}
-	if (priv == NULL) {
-		if (error_r != NULL)
-			*error_r = "key is NULL";
-		return FALSE;
-	}
 
 	return dcrypt_openssl_public_key_id_evp(priv, md, result, error_r);
 }