[openssl] master update

nic.tuv at gmail.com nic.tuv at gmail.com
Mon Mar 30 14:07:21 UTC 2020


The branch master has been updated
       via  fd03868b34faaa711403d9ac0843d33811fbf961 (commit)
       via  551543e5e2779fbb242cca40813f3bea4f6f43d0 (commit)
      from  e15d369781eb2e97656ebbabef576b8079d86b8c (commit)


- Log -----------------------------------------------------------------
commit fd03868b34faaa711403d9ac0843d33811fbf961
Author: Nicola Tuveri <nicola.tuveri at ibm.com>
Date:   Fri Mar 27 15:39:34 2020 +0100

    Fix off-by-1 bug on provider_activate with custom error strings
    
    Starting `cnt` from 1 would work if we weren't using cnt itself to
    access elements of the array returned calling the provider callback.
    
    As it is before this commit, we have 2 problems:
    - first, in the unlikely case that the incoming array was "empty" (only
      contains the terminator item) we would skip past it and potentially
      end up with oob reads;
    - otherwise, at the end of the while loop, `cnt` will be equal to the
      number of items in the input array, not 1 more. We then add 1 more to
      the zalloc call to account for the library name item, and we fill all
      of it (relying on zalloc to have zeroed the terminator item).
      The first read access that will read the list up to the terminator
      will result in a OOB read as we did not allocate enough space to also
      contain the terminator.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/11427)

commit 551543e5e2779fbb242cca40813f3bea4f6f43d0
Author: Nicola Tuveri <nicola.tuveri at ibm.com>
Date:   Fri Mar 27 12:02:48 2020 +0100

    Add test for providers exposing OSSL_FUNC_PROVIDER_GET_REASON_STRINGS
    
    This test currently fails, next commit has the description of the bug
    and the fix.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/11427)

-----------------------------------------------------------------------

Summary of changes:
 crypto/provider_core.c |  3 ++-
 test/p_test.c          | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/crypto/provider_core.c b/crypto/provider_core.c
index 2a463550d6..ef8b3bf5b4 100644
--- a/crypto/provider_core.c
+++ b/crypto/provider_core.c
@@ -540,12 +540,13 @@ static int provider_activate(OSSL_PROVIDER *prov)
          * with the error library number, so we need to make a copy of that
          * array either way.
          */
-        cnt = 1;                 /* One for the terminating item */
+        cnt = 0;
         while (reasonstrings[cnt].id != 0) {
             if (ERR_GET_LIB(reasonstrings[cnt].id) != 0)
                 return 0;
             cnt++;
         }
+        cnt++;                   /* One for the terminating item */
 
         /* Allocate one extra item for the "library" name */
         prov->error_strings =
diff --git a/test/p_test.c b/test/p_test.c
index bc354be95d..ac1f4c200d 100644
--- a/test/p_test.c
+++ b/test/p_test.c
@@ -41,6 +41,7 @@ static const OSSL_PARAM p_param_types[] = {
 /* This is a trick to ensure we define the provider functions correctly */
 static OSSL_provider_gettable_params_fn p_gettable_params;
 static OSSL_provider_get_params_fn p_get_params;
+static OSSL_provider_get_reason_strings_fn p_get_reason_strings;
 
 static const OSSL_PARAM *p_gettable_params(void *_)
 {
@@ -100,9 +101,21 @@ static int p_get_params(void *vprov, OSSL_PARAM params[])
     return ok;
 }
 
+static const OSSL_ITEM *p_get_reason_strings(void *_)
+{
+    static const OSSL_ITEM reason_strings[] = {
+        {1, "dummy reason string"},
+        {0, NULL}
+    };
+
+    return reason_strings;
+}
+
 static const OSSL_DISPATCH p_test_table[] = {
     { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))p_gettable_params },
     { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))p_get_params },
+    { OSSL_FUNC_PROVIDER_GET_REASON_STRINGS,
+        (void (*)(void))p_get_reason_strings},
     { 0, NULL }
 };
 


More information about the openssl-commits mailing list