OSSL_DECODER_from_bio: Report an unsupported error when there is none
authorTomas Mraz <tomas@openssl.org>
Tue, 25 May 2021 07:59:06 +0000 (09:59 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 26 May 2021 11:04:38 +0000 (13:04 +0200)
When nothing was decoded and there is no error on the stack report
something.

Fixes #15442

Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15441)

crypto/encode_decode/decoder_lib.c

index c7eac0eddd6e554d58546d4206d616b93cb075cb..022c1d56e2e2393d1e660c5d2e942a6921b775bc 100644 (file)
@@ -87,9 +87,10 @@ 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 /* Prevent spurious decoding error */)
+        if (BIO_eof(in) == 0 || ERR_peek_error() == 0)
+            /* Prevent spurious decoding error */
             ERR_raise_data(ERR_LIB_OSSL_DECODER, ERR_R_UNSUPPORTED,
-                           "Not supported for the data to decode.%s%s%s%s%s%s",
+                           "No supported data to decode. %s%s%s%s%s%s",
                            spaces, input_type_label, input_type, comma,
                            input_structure_label, input_structure);
         ok = 0;