The branch master has been updated via 1010e4ac9743a273d12e4f7c49959607aa4f6403 (commit) via 2b748d722b6ac560d122ea2dcf8d09fe6f03124b (commit) from 2c0e356ef7fdbb117c9294b57deb67be66db3470 (commit)
- Log ----------------------------------------------------------------- commit 1010e4ac9743a273d12e4f7c49959607aa4f6403 Author: Todd Short <tsh...@akamai.com> Date: Tue Sep 1 14:50:03 2020 -0400 Fix post-condition in algorithm_do_this Reviewed-by: Richard Levitte <levi...@openssl.org> Reviewed-by: Matt Caswell <m...@openssl.org> Reviewed-by: Ben Kaduk <ka...@mit.edu> (Merged from https://github.com/openssl/openssl/pull/12760) commit 2b748d722b6ac560d122ea2dcf8d09fe6f03124b Author: Todd Short <tsh...@akamai.com> Date: Mon Aug 31 19:59:43 2020 -0400 Fix use of OPENSSL_realloc in provider Fix OPENSSL_realloc failure case; `provider->operation_bits` memory is lost when `OPENSSL_realloc()` returns NULL. `operation_bits_sz` is never set to the length of the allocated array. This means that operation_bits is always reallocated in `ossl_provider_set_operation_bit()`, possibly shrinking the array. In addition, it means that the `memset()` always zeros out the whole reallocated array, not just the new part. Also, because `operation_bits_sz` is always zero, the value of `*result` in `ossl_provider_test_operation_bit()` will always be zero. Reviewed-by: Richard Levitte <levi...@openssl.org> Reviewed-by: Matt Caswell <m...@openssl.org> Reviewed-by: Ben Kaduk <ka...@mit.edu> (Merged from https://github.com/openssl/openssl/pull/12760) ----------------------------------------------------------------------- Summary of changes: crypto/core_algorithm.c | 8 ++++---- crypto/provider_core.c | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crypto/core_algorithm.c b/crypto/core_algorithm.c index f4a20cb2d1..68d6129598 100644 --- a/crypto/core_algorithm.c +++ b/crypto/core_algorithm.c @@ -31,7 +31,7 @@ static int algorithm_do_this(OSSL_PROVIDER *provider, void *cbdata) int first_operation = 1; int last_operation = OSSL_OP__HIGHEST; int cur_operation; - int ok = 0; + int ok = 1; if (data->operation_id != 0) first_operation = last_operation = data->operation_id; @@ -77,9 +77,9 @@ static int algorithm_do_this(OSSL_PROVIDER *provider, void *cbdata) return 0; } - /* If post-condition fulfilled, set general success */ - if (ret) - ok = 1; + /* If post-condition not fulfilled, set general failure */ + if (!ret) + ok = 0; } return ok; diff --git a/crypto/provider_core.c b/crypto/provider_core.c index a714a71681..f282071e2d 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -875,14 +875,17 @@ int ossl_provider_set_operation_bit(OSSL_PROVIDER *provider, size_t bitnum) unsigned char bit = (1 << (bitnum % 8)) & 0xFF; if (provider->operation_bits_sz <= byte) { - provider->operation_bits = OPENSSL_realloc(provider->operation_bits, - byte + 1); - if (provider->operation_bits == NULL) { + unsigned char *tmp = OPENSSL_realloc(provider->operation_bits, + byte + 1); + + if (tmp == NULL) { ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE); return 0; } + provider->operation_bits = tmp; memset(provider->operation_bits + provider->operation_bits_sz, '\0', byte + 1 - provider->operation_bits_sz); + provider->operation_bits_sz = byte + 1; } provider->operation_bits[byte] |= bit; return 1;