From 40692ed7c80ae3bb6c92c674fb90a5e15d81052d Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Sat, 15 May 2021 10:27:09 +0100 Subject: Better error messages if there are no encoders/decoders/store loaders If you don't have the base or default providers loaded and therefore there are no encoders/decoders or store loaders then the error messages can be cryptic. We provide better hints about how to fix the problem. Fixes #13798 Reviewed-by: Paul Dale Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/15306) --- crypto/encode_decode/decoder_err.c | 2 ++ crypto/encode_decode/decoder_lib.c | 8 ++++++++ crypto/encode_decode/encoder_lib.c | 8 ++++++++ 3 files changed, 18 insertions(+) (limited to 'crypto/encode_decode') diff --git a/crypto/encode_decode/decoder_err.c b/crypto/encode_decode/decoder_err.c index 1880c8f409..c948d82698 100644 --- a/crypto/encode_decode/decoder_err.c +++ b/crypto/encode_decode/decoder_err.c @@ -17,6 +17,8 @@ static const ERR_STRING_DATA OSSL_DECODER_str_reasons[] = { {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT), "could not decode object"}, + {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_DECODER_NOT_FOUND), + "decoder not found"}, {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_GET_PARAMS), "missing get params"}, {0, NULL} diff --git a/crypto/encode_decode/decoder_lib.c b/crypto/encode_decode/decoder_lib.c index 8a5082c441..c7eac0eddd 100644 --- a/crypto/encode_decode/decoder_lib.c +++ b/crypto/encode_decode/decoder_lib.c @@ -48,6 +48,14 @@ int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in) int ok = 0; BIO *new_bio = NULL; + if (OSSL_DECODER_CTX_get_num_decoders(ctx) == 0) { + ERR_raise_data(ERR_LIB_OSSL_DECODER, OSSL_DECODER_R_DECODER_NOT_FOUND, + "No decoders were found. For standard decoders you need " + "at least one of the default or base providers " + "available. Did you forget to load them?"); + return 0; + } + if (BIO_tell(in) < 0) { new_bio = BIO_new(BIO_f_readbuffer()); if (new_bio == NULL) diff --git a/crypto/encode_decode/encoder_lib.c b/crypto/encode_decode/encoder_lib.c index ea0a556e56..f074c9fb60 100644 --- a/crypto/encode_decode/encoder_lib.c +++ b/crypto/encode_decode/encoder_lib.c @@ -49,6 +49,14 @@ int OSSL_ENCODER_to_bio(OSSL_ENCODER_CTX *ctx, BIO *out) data.bio = out; data.current_encoder_inst_index = OSSL_ENCODER_CTX_get_num_encoders(ctx); + if (data.current_encoder_inst_index == 0) { + ERR_raise_data(ERR_LIB_OSSL_ENCODER, OSSL_ENCODER_R_ENCODER_NOT_FOUND, + "No encoders were found. For standard encoders you need " + "at least one of the default or base providers " + "available. Did you forget to load them?"); + return 0; + } + return encoder_process(&data) > 0; } -- cgit v1.2.1