From 3b3892373596f544d297b45704654aeacc60d170 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 6 Dec 2023 16:29:50 -0500 Subject: [PATCH] fixes #2119 -- use ErrorStack abstraction in X.509 error handling --- openssl/src/x509/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 8458e7313d..328be5b25f 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -383,11 +383,6 @@ foreign_type_and_impl_send_sync! { pub struct X509Ref; } -#[cfg(boringssl)] -type X509LenTy = c_uint; -#[cfg(not(boringssl))] -type X509LenTy = c_int; - impl X509Ref { /// Returns this certificate's subject name. #[corresponds(X509_get_subject_name)] @@ -760,15 +755,16 @@ impl X509 { let r = ffi::PEM_read_bio_X509(bio.as_ptr(), ptr::null_mut(), None, ptr::null_mut()); if r.is_null() { - let err = ffi::ERR_peek_last_error(); - if ffi::ERR_GET_LIB(err) as X509LenTy == ffi::ERR_LIB_PEM - && ffi::ERR_GET_REASON(err) == ffi::PEM_R_NO_START_LINE + let e = ErrorStack::get(); + let errors = e.errors(); + if !errors.is_empty() + && errors[0].library_code() == ffi::ERR_LIB_PEM as libc::c_int + && errors[0].reason_code() == ffi::PEM_R_NO_START_LINE as libc::c_int { - ffi::ERR_clear_error(); break; } - return Err(ErrorStack::get()); + return Err(e); } else { certs.push(X509(r)); }