From cd5d6a5004edf3fa56c82f5f6bd06163b02c90ea Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Thu, 30 Jun 2022 10:11:21 +0200 Subject: [PATCH] libpv/cert.c: Improve error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation drops the reason why a download of a CRL failed. This is changed to the reporting of the error triggered by the last CRL download attempt. This mainly helps to check for the download error during CI testing and prevent connectivity issues to be the reason of a test failure. Signed-off-by: Steffen Eiden Reviewed-by: Marc Hartmayer Signed-off-by: Jan Höppner --- libpv/cert.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libpv/cert.c b/libpv/cert.c index 4cd94211..064cc92d 100644 --- a/libpv/cert.c +++ b/libpv/cert.c @@ -492,7 +492,9 @@ static X509_CRL *load_crl_by_dist_point(DIST_POINT *crldp, GError **error) X509_CRL *pv_load_first_crl_by_cert(X509 *cert, GError **error) { g_autoptr(STACK_OF_DIST_POINT) crldps = NULL; + g_autoptr(GError) last_error = NULL; g_autoptr(X509_CRL) ret = NULL; + int dist_points_cnt; g_assert(cert); @@ -503,19 +505,24 @@ X509_CRL *pv_load_first_crl_by_cert(X509 *cert, GError **error) return NULL; } - for (int i = 0; i < sk_DIST_POINT_num(crldps); i++) { + dist_points_cnt = sk_DIST_POINT_num(crldps); + for (int i = 0; i < dist_points_cnt; i++) { DIST_POINT *crldp = sk_DIST_POINT_value(crldps, i); - g_assert(crldp); - /* ignore error */ - ret = load_crl_by_dist_point(crldp, NULL); + g_clear_error(&last_error); + ret = load_crl_by_dist_point(crldp, &last_error); if (ret) return g_steal_pointer(&ret); } - g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_FAILED_DOWNLOAD_CRL, - _("failed to download CRL")); + /* relabel error */ + if (last_error) + g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_FAILED_DOWNLOAD_CRL, + "%s", last_error->message); + else + g_set_error(error, PV_CERT_ERROR, PV_CERT_ERROR_FAILED_DOWNLOAD_CRL, + _("failed to download CRL")); return NULL; }