changeset 20221:88b3f095925b

lib-dcrypt: Always allow error_r to be NULL. Especially dcrypt_openssl_private_to_public_key() was called with error_r=NULL by the dcrypt.c itself.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 30 May 2016 21:14:53 +0300
parents c543c8da9714
children f20e271a7ff4
files src/lib-dcrypt/dcrypt-openssl.c
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dcrypt/dcrypt-openssl.c	Mon May 30 19:38:22 2016 +0300
+++ b/src/lib-dcrypt/dcrypt-openssl.c	Mon May 30 21:14:53 2016 +0300
@@ -385,7 +385,8 @@
 	const EVP_MD *md;
 	md = EVP_get_digestbyname(algorithm);
 	if(md == NULL) {
-		*error_r = t_strdup_printf("Invalid digest %s", algorithm);
+		if (error_r != NULL)
+			*error_r = t_strdup_printf("Invalid digest %s", algorithm);
 		return FALSE;
 	}
 	/* allocate context */
@@ -673,7 +674,8 @@
 		/* determine MD */
 		const EVP_MD* md = EVP_get_digestbyname(hash);
 		if (md == NULL) {
-			*error_r = t_strdup_printf("Invalid digest %s", hash);
+			if (error_r != NULL)
+				*error_r = t_strdup_printf("Invalid digest %s", hash);
 			return FALSE;
 		}
 
@@ -1550,7 +1552,8 @@
 	if (cipher != NULL) {
 		algo = EVP_get_cipherbyname(cipher);
 		if (algo == NULL) {
-			*error_r = t_strdup_printf("Invalid cipher %s", cipher);
+			if (error_r != NULL)
+				*error_r = t_strdup_printf("Invalid cipher %s", cipher);
 			return FALSE;
 		}
 	}
@@ -1630,7 +1633,8 @@
 		EVP_PKEY_set1_EC_KEY(pk, eck);
 		EC_KEY_free(eck);
 	} else {
-		*error_r = "Invalid private key";
+		if (error_r != NULL)
+			*error_r = "Invalid private key";
 		return FALSE;
 	}