Skip to content

Commit

Permalink
Zlib: Don't leave errors behind if loading library failed.
Browse files Browse the repository at this point in the history
If zlib support is dynamic then it is loaded at runtime and may fail
if the library is not available. The library can be loaded even if the
user did not ask for it, for instance via SSL_CTX_new_ex() ->
ossl_comp_has_alg().
Leaving an error record can have other side effects if the user is
poping the stack and notices and aborts due it.

Use ERR_set_mark()/ ERR_pop_to_mark() to avoid leaving marks if library
loading failed. Use ERR_clear_last_mark() if loading succeeded.

Fixes: openssl#23558
Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
  • Loading branch information
sebastianas committed Feb 15, 2024
1 parent 3e3a068 commit a461f91
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crypto/comp/c_zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_comp_zlib_init)
# endif
# endif

ERR_set_mark();
zlib_dso = DSO_load(NULL, LIBZ, NULL, 0);
if (zlib_dso != NULL) {
p_compress = (compress_ft) DSO_bind_func(zlib_dso, "compress");
Expand All @@ -299,9 +300,11 @@ DEFINE_RUN_ONCE_STATIC(ossl_comp_zlib_init)
|| p_deflateEnd == NULL || p_deflate == NULL
|| p_deflateInit_ == NULL || p_zError == NULL) {
ossl_comp_zlib_cleanup();
ERR_pop_to_mark();
return 0;
}
}
ERR_clear_last_mark();
# endif
return 1;
}
Expand Down

0 comments on commit a461f91

Please sign in to comment.