eet, emile: safety++ 02/253002/3 accepted/tizen/unified/20210208.061652 submit/tizen/20210204.012753
authorShinwoo Kim <cinoo.kim@samsung.com>
Thu, 4 Feb 2021 01:11:16 +0000 (10:11 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Thu, 4 Feb 2021 01:18:46 +0000 (01:18 +0000)
Summary:
(1) EVP_MD_CTX_new could return NULL
(2) EVP_DigestUpdate returns 0 for failure.
  https://www.openssl.org/docs/man1.0.2/man3/EVP_DigestUpdate.html

Reviewers: raster, Hermet, cedric, devilhorns

Reviewed By: devilhorns

Subscribers: SPAM-roll99, devilhorns, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D12237

Change-Id: If86106c318e91754010eca27bfd5ee898c49f0d1

src/lib/eet/eet_cipher.c
src/lib/emile/emile_cipher_openssl.c

index 51f8513..025750c 100644 (file)
@@ -564,6 +564,11 @@ eet_identity_sign(FILE    *fp,
    /* Do the signature. */
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
    md_ctx = EVP_MD_CTX_new();
+   if (!md_ctx)
+     {
+        err = EET_ERROR_OUT_OF_MEMORY;
+        goto on_error;
+     }
    EVP_SignInit(md_ctx, EVP_sha1());
    EVP_SignUpdate(md_ctx, data, st_buf.st_size);
    err = EVP_SignFinal(md_ctx,
@@ -776,6 +781,16 @@ eet_identity_check(const void   *data_base,
    /* Verify the signature */
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
    md_ctx = EVP_MD_CTX_new();
+   if (!md_ctx)
+     {
+        err = EET_ERROR_OUT_OF_MEMORY;
+
+        X509_free(x509);
+        EVP_PKEY_free(pkey);
+
+        return NULL;
+     }
+
    EVP_VerifyInit(md_ctx, EVP_sha1());
    EVP_VerifyUpdate(md_ctx, data_base, data_length);
    err = EVP_VerifyFinal(md_ctx, sign, sign_len, pkey);
index b09897e..e5a1ed4 100644 (file)
@@ -75,10 +75,16 @@ emile_binbuf_sha1(const Eina_Binbuf * data, unsigned char digest[20])
    Eina_Slice slice = eina_binbuf_slice_get(data);
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
+   if (!ctx) return EINA_FALSE;
 
    EVP_DigestInit_ex(ctx, md, NULL);
 
-   EVP_DigestUpdate(ctx, slice.mem, slice.len);
+   if (!EVP_DigestUpdate(ctx, slice.mem, slice.len))
+     {
+        EVP_MD_CTX_free(ctx);
+        return EINA_FALSE;
+     }
+
    EVP_DigestFinal_ex(ctx, digest, NULL);
 
    EVP_MD_CTX_free(ctx);