Set mark and pop error in d2i_PrivateKey_ex
authorDaniel Bevenius <daniel.bevenius@gmail.com>
Mon, 5 Oct 2020 06:14:29 +0000 (08:14 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Thu, 8 Oct 2020 15:53:21 +0000 (17:53 +0200)
commitd00bd4e452e846a610284fe2be3e9358153251e7
tree18556172678dfb19f58edc36bb0742a613609449
parent13c5ec569ea9286ff18e019fb2d53be64829c62c
Set mark and pop error in d2i_PrivateKey_ex

This commit sets the error mark before calling old_priv_decode and if
old_priv_decode returns false, and if EVP_PKCS82PKEY is successful, the
errors are popped to the previously set mark.

The motivation for this is an issue we found when linking Node.js
against OpenSSL 3.0. Details can be found in the link below and the
test case provided in this commit attempts cover this.

Refs: https://github.com/danbev/learning-libcrypto#asn1-wrong-tag-issue
Refs: https://github.com/nodejs/node/issues/29817

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13073)
crypto/asn1/d2i_pr.c
test/evp_extra_test2.c