From 63636301593c8a3952afae61c1b5f279c27f69ea Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Mon, 31 Jul 2017 23:06:33 -0400 Subject: Unconditionally set the allocated flag when initializing a hash state structure. When running multiple concurrent unit tests, I observed multiple failures in the hmac tests, which I ultimately tracked down to different clients sharing the same hal_hmac_state struct. hal_hash_initialize is called twice in hal_hmac_initialize (once to get the state structure, then again if the supplied key is too long), and is called in hal_hmac_finalize, to hash the digest with the supplied key. In these subsequent cases, the caller supplies the state structure, which hal_hash_initialize zeroes, but it doesn't set the allocated flag. This marks an in-use struct as available, so it gets reassigned and reinitialized, and Bad Things Happen for both clients that are trying to use it. --- hash.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/hash.c b/hash.c index 2c745a8..fa30b60 100644 --- a/hash.c +++ b/hash.c @@ -443,10 +443,7 @@ hal_error_t hal_hash_initialize(hal_core_t *core, state->descriptor = descriptor; state->driver = driver; state->core = core; - state->flags = flags; - - if (state_buffer == NULL) - state->flags |= STATE_FLAG_STATE_ALLOCATED; + state->flags = flags | STATE_FLAG_STATE_ALLOCATED; *state_ = state; @@ -777,9 +774,6 @@ hal_error_t hal_hmac_initialize(hal_core_t *core, sizeof(state->hash_state))) != HAL_OK) goto fail; - if (state_buffer == NULL) - h->flags |= STATE_FLAG_STATE_ALLOCATED; - /* * If the supplied HMAC key is longer than the hash block length, we * need to hash the supplied HMAC key to get the real HMAC key. -- cgit v1.2.3