summaryrefslogtreecommitdiffstats
path: root/crypto/encode_decode
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-06-23 13:53:58 +0200
committerTomas Mraz <tomas@openssl.org>2021-06-24 15:26:56 +0200
commitab7554e5a08966c159054ae7df18a879bfe3865f (patch)
tree7ce5b916dddf80d1c6764b70a3499c61830c1434 /crypto/encode_decode
parent42fe3e849362e17c8baac3901087e5130eebd5a7 (diff)
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 <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15878)
Diffstat (limited to 'crypto/encode_decode')
-rw-r--r--crypto/encode_decode/decoder_lib.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c
index c637b5bfef..938f97c282 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,