diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-06-29 15:46:25 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-07-02 15:33:27 +0200 |
commit | fbbd425336144455f4a976acd7b890352ef7ed38 (patch) | |
tree | 052bbebf1c945fcf0bda0b55162d6ff780630a06 /crypto/pem | |
parent | 92d7120c60cea7c9e0219921c2cc2320346218b2 (diff) | |
download | openssl-new-fbbd425336144455f4a976acd7b890352ef7ed38.tar.gz |
pem_read_bio_key_decoder: Avoid spurious error on unknown PEM data
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15949)
Diffstat (limited to 'crypto/pem')
-rw-r--r-- | crypto/pem/pem_pkey.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index ca6b2a2132..4a029daa95 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -55,11 +55,24 @@ static EVP_PKEY *pem_read_bio_key_decoder(BIO *bp, EVP_PKEY **x, if (!OSSL_DECODER_CTX_set_pem_password_cb(dctx, cb, u)) goto err; + ERR_set_mark(); while (!OSSL_DECODER_from_bio(dctx, bp) || pkey == NULL) - if (BIO_eof(bp) != 0 || (newpos = BIO_tell(bp)) < 0 || newpos <= pos) + if (BIO_eof(bp) != 0 || (newpos = BIO_tell(bp)) < 0 || newpos <= pos) { + ERR_clear_last_mark(); goto err; - else + } else { + if (ERR_GET_REASON(ERR_peek_error()) == ERR_R_UNSUPPORTED) { + /* unsupported PEM data, try again */ + ERR_pop_to_mark(); + ERR_set_mark(); + } else { + /* other error, bail out */ + ERR_clear_last_mark(); + goto err; + } pos = newpos; + } + ERR_pop_to_mark(); if (!evp_keymgmt_util_has(pkey, selection)) { EVP_PKEY_free(pkey); |