]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: Assert-crash if key parameter is NULL.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 19 Jun 2016 17:55:19 +0000 (20:55 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Jun 2016 18:43:07 +0000 (21:43 +0300)
If it happens, it's a bug.

src/lib-dcrypt/dcrypt-openssl.c

index 99803f02aa2b9c58bd07c7449c4d395a7ec810a6..4e055b4ecdaab4659eaaf04ef0f928e4684f18b9 100644 (file)
@@ -1658,11 +1658,7 @@ bool dcrypt_openssl_key_string_get_info(const char *key_data, enum dcrypt_key_fo
        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 @@ bool dcrypt_openssl_public_key_id_old(struct dcrypt_public_key *key, buffer_t *r
        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 @@ bool dcrypt_openssl_private_key_id_old(struct dcrypt_private_key *key, buffer_t
        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 @@ bool dcrypt_openssl_public_key_id(struct dcrypt_public_key *key, const char *alg
        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 @@ bool dcrypt_openssl_private_key_id(struct dcrypt_private_key *key, const char *a
        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);
 }