Skip to content

Commit a3d3449

Browse files
authored
Merge pull request #2120 from alex/improve-error-handling
fixes #2119 -- use ErrorStack abstraction in X.509 error handling
2 parents c428588 + 3b38923 commit a3d3449

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

openssl/src/x509/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,6 @@ foreign_type_and_impl_send_sync! {
383383
pub struct X509Ref;
384384
}
385385

386-
#[cfg(boringssl)]
387-
type X509LenTy = c_uint;
388-
#[cfg(not(boringssl))]
389-
type X509LenTy = c_int;
390-
391386
impl X509Ref {
392387
/// Returns this certificate's subject name.
393388
#[corresponds(X509_get_subject_name)]
@@ -760,15 +755,16 @@ impl X509 {
760755
let r =
761756
ffi::PEM_read_bio_X509(bio.as_ptr(), ptr::null_mut(), None, ptr::null_mut());
762757
if r.is_null() {
763-
let err = ffi::ERR_peek_last_error();
764-
if ffi::ERR_GET_LIB(err) as X509LenTy == ffi::ERR_LIB_PEM
765-
&& ffi::ERR_GET_REASON(err) == ffi::PEM_R_NO_START_LINE
758+
let e = ErrorStack::get();
759+
let errors = e.errors();
760+
if !errors.is_empty()
761+
&& errors[0].library_code() == ffi::ERR_LIB_PEM as libc::c_int
762+
&& errors[0].reason_code() == ffi::PEM_R_NO_START_LINE as libc::c_int
766763
{
767-
ffi::ERR_clear_error();
768764
break;
769765
}
770766

771-
return Err(ErrorStack::get());
767+
return Err(e);
772768
} else {
773769
certs.push(X509(r));
774770
}

0 commit comments

Comments
 (0)