Tolerate 0 byte input length for Update functions
authorMatt Caswell <matt@openssl.org>
Tue, 26 Mar 2019 15:25:15 +0000 (15:25 +0000)
committerMatt Caswell <matt@openssl.org>
Wed, 27 Mar 2019 10:14:03 +0000 (10:14 +0000)
We treat that as automatic success. Other EVP_*Update functions already do
this (e.g. EVP_EncryptUpdate, EVP_DecryptUpdate etc). EVP_EncodeUpdate is
a bit of an anomoly. That treats 0 byte input length as an error.

Fixes #8576

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8587)

crypto/evp/digest.c
crypto/evp/mac_lib.c

index d4b481443c1e0fd20371a6af25f484edba710298..7b4972553b92b618ce5b6727858759e2acbee766 100644 (file)
@@ -259,6 +259,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
 
 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
 {
+    if (count == 0)
+        return 1;
+
     if (ctx->digest == NULL || ctx->digest->prov == NULL)
         goto legacy;
 
index 2f46277bf0069a2a142b673853368e618decd73c..39efff0842217e6c5e6aa4830c1dd37c1db5d75b 100644 (file)
@@ -82,6 +82,8 @@ int EVP_MAC_init(EVP_MAC_CTX *ctx)
 
 int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen)
 {
+    if (datalen == 0)
+        return 1;
     return ctx->meth->update(ctx->data, data, datalen);
 }