From ab7554e5a08966c159054ae7df18a879bfe3865f Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Wed, 23 Jun 2021 13:53:58 +0200 Subject: [PATCH] OSSL_DECODER_from_bio: Avoid spurious decoder error If there are any new errors reported we avoid raising the OSSL_DECODER_from_bio:unsupported error. Fixes #14566 Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15878) --- crypto/encode_decode/decoder_lib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index c637b5bfefe..938f97c2820 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -47,6 +47,7 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) struct decoder_process_data_st data; int ok = 0; BIO *new_bio = NULL; + unsigned long lasterr; if (in == NULL) { ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_PASSED_NULL_PARAMETER); @@ -61,6 +62,8 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) return 0; } + lasterr = ERR_peek_last_error(); + if (BIO_tell(in) < 0) { new_bio = BIO_new(BIO_f_readbuffer()); if (new_bio == NULL) @@ -92,8 +95,8 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) const char *input_structure = ctx->input_structure != NULL ? ctx->input_structure : ""; - if (BIO_eof(in) == 0 || ERR_peek_error() == 0) - /* Prevent spurious decoding error */ + if (ERR_peek_last_error() == lasterr || ERR_peek_error() == 0) + /* Prevent spurious decoding error but add at least something */ ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_UNSUPPORTED, "No supported data to decode. %s%s%s%s%s%s", spaces, input_type_label, input_type, comma, -- 2.47.2