Fix init_get_thread_local()
authorDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Wed, 17 Jul 2019 17:14:01 +0000 (19:14 +0200)
committerDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Thu, 18 Jul 2019 04:20:55 +0000 (06:20 +0200)
commit3b438ef95b5b1c45602b1332921209363e4776bd
tree3e8f343ff7c0c7eae81d154414caa4d6dd6f3813
parente7aa7c11c71e84b2d6c06b1c81d130e8c1fba296
Fix init_get_thread_local()

Previously, init_get_thread_local() pushed the thread event handler
list onto the global register before calling CRYPTO_THREAD_set_local(),
and when the latter failed, forgot to pop the list from the stack again.

Instead of cleaning the stack on error, this commit avoids the situation
entirely by postponing the push operation until all other operations
succeeded. This reordering also significantly reduces the scope of the
critical section.

Another simplification of the code is achieved by moving the push operation
onto the register (which is disabled in FIPS mode) into a separate function.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9401)
crypto/initthread.c