OSSL_DECODER_from_bio: Avoid spurious decoder error
authorTomas Mraz <tomas@openssl.org>
Wed, 23 Jun 2021 11:53:58 +0000 (13:53 +0200)
committerTomas Mraz <tomas@openssl.org>
Thu, 24 Jun 2021 13:26:56 +0000 (15:26 +0200)
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)

crypto/encode_decode/decoder_lib.c

index c637b5bfefe7ec920208fe5bcb61e4fe1d1abfe9..938f97c2820551963655492c0a51512ac37cc9de 100644 (file)
@@ -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,