Don't leave stale errors on queue if DSO_dsobyaddr() fails

The init code uses DSO_dsobyaddr() to leak a reference to ourselves to
ensure we remain loaded until atexit() time. In some circumstances that
can fail and leave stale errors on the error queue.

Fixes #3372

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3383)
This commit is contained in:
Matt Caswell 2017-05-04 12:51:18 +01:00
parent de6ac50ddc
commit 689f112d98

View file

@ -107,13 +107,15 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base)
# else
/*
* Deliberately leak a reference to ourselves. This will force the library
* to remain loaded until the atexit() handler is run a process exit.
* to remain loaded until the atexit() handler is run at process exit.
*/
{
DSO *dso = NULL;
ERR_set_mark();
dso = DSO_dsobyaddr(&base_inited, DSO_FLAG_NO_UNLOAD_ON_FREE);
DSO_free(dso);
ERR_pop_to_mark();
}
# endif
#endif
@ -648,8 +650,10 @@ int OPENSSL_atexit(void (*handler)(void))
{
DSO *dso = NULL;
ERR_set_mark();
dso = DSO_dsobyaddr(handlersym.sym, DSO_FLAG_NO_UNLOAD_ON_FREE);
DSO_free(dso);
ERR_pop_to_mark();
}
# endif
}