Skip to content

Commit

Permalink
error.rs: eliminate an unsafe using c"" strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Apr 10, 2024
1 parent 4dec4f3 commit e9b14ae
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions rustls-libssl/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ffi::{c_int, c_long};
use core::ptr;
use std::ffi::{CStr, CString};
use std::ffi::CString;

use openssl_sys::{ERR_new, ERR_set_error, ERR_RFLAGS_OFFSET, ERR_RFLAG_FATAL};
use rustls::AlertDescription;
Expand Down Expand Up @@ -125,16 +125,14 @@ impl Error {
.unwrap_or_else(|| format!("{:?}", self.reason)),
)
.unwrap();
// safety: b"%s\0" satisfies requirements of from_bytes_with_nul_unchecked.
let fmt = unsafe { CStr::from_bytes_with_nul_unchecked(b"%s\0") };
unsafe {
ERR_new();
// nb. miri cannot do variadic functions, so we define a miri-only equivalent
#[cfg(not(miri))]
ERR_set_error(
self.lib as c_int,
self.reason.into(),
fmt.as_ptr(),
c"%s".as_ptr(),
cstr.as_ptr(),
);
#[cfg(miri)]
Expand Down

0 comments on commit e9b14ae

Please sign in to comment.