From f42250ca9bed6ff187fd4f6bd3c5506fe437a057 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Thu, 21 Jul 2022 12:38:32 +0200 Subject: [PATCH] genprotimg: Fix BIO_reset() returncode handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The returncode handling for BIO_reset() was wrong when handling with file based BIOs. This resulted in a bug that DER formated certificates cannot be read by genprotimg which is now fixed. Fixes: d90344a2 (genprotimg: check return value of BIO_reset) Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Signed-off-by: Jan Höppner --- genprotimg/src/utils/crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genprotimg/src/utils/crypto.c b/genprotimg/src/utils/crypto.c index 7745b392..d4943b6d 100644 --- a/genprotimg/src/utils/crypto.c +++ b/genprotimg/src/utils/crypto.c @@ -447,7 +447,7 @@ static X509_CRL *load_crl_from_bio(BIO *bio) return g_steal_pointer(&crl); ERR_clear_error(); rc = BIO_reset(bio); - if (rc != 1 || (rc != 0 && BIO_method_type(bio) == BIO_TYPE_FILE)) + if (rc != 1 && !(rc == 0 && BIO_method_type(bio) == BIO_TYPE_FILE)) return NULL; /* maybe the CRL is stored in DER format */ @@ -533,7 +533,7 @@ X509 *load_cert_from_file(const char *path, GError **err) return g_steal_pointer(&cert); ERR_clear_error(); rc = BIO_reset(bio); - if (rc != 1 || (rc != 0 && BIO_method_type(bio) == BIO_TYPE_FILE)) { + if (rc != 1 && !(rc == 0 && BIO_method_type(bio) == BIO_TYPE_FILE)) { g_set_error(err, PV_CRYPTO_ERROR, PV_CRYPTO_ERROR_READ_CERTIFICATE, _("unable to load certificate: '%s'"), path); return NULL;