Skip to content

Commit b2552c1

Browse files
operutkaoverminder
authored andcommitted
Cast correctly c_char raw pointers (fixes build on ARM sfackler#314)
1 parent 6b25f1b commit b2552c1

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

openssl/src/bn/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ impl BigNum {
8989
pub fn from_dec_str(s: &str) -> Result<BigNum, SslError> {
9090
BigNum::new().and_then(|v| unsafe {
9191
let c_str = CString::new(s.as_bytes()).unwrap();
92-
try_ssl!(ffi::BN_dec2bn(v.raw_ptr(), c_str.as_ptr()));
92+
try_ssl!(ffi::BN_dec2bn(v.raw_ptr(), c_str.as_ptr() as *const _));
9393
Ok(v)
9494
})
9595
}
9696

9797
pub fn from_hex_str(s: &str) -> Result<BigNum, SslError> {
9898
BigNum::new().and_then(|v| unsafe {
9999
let c_str = CString::new(s.as_bytes()).unwrap();
100-
try_ssl!(ffi::BN_hex2bn(v.raw_ptr(), c_str.as_ptr()));
100+
try_ssl!(ffi::BN_hex2bn(v.raw_ptr(), c_str.as_ptr() as *const _));
101101
Ok(v)
102102
})
103103
}
@@ -421,7 +421,7 @@ impl BigNum {
421421
unsafe {
422422
let buf = ffi::BN_bn2dec(self.raw());
423423
assert!(!buf.is_null());
424-
let str = String::from_utf8(CStr::from_ptr(buf).to_bytes().to_vec()).unwrap();
424+
let str = String::from_utf8(CStr::from_ptr(buf as *const _).to_bytes().to_vec()).unwrap();
425425
ffi::CRYPTO_free(buf as *mut c_void);
426426
str
427427
}
@@ -431,7 +431,7 @@ impl BigNum {
431431
unsafe {
432432
let buf = ffi::BN_bn2hex(self.raw());
433433
assert!(!buf.is_null());
434-
let str = String::from_utf8(CStr::from_ptr(buf).to_bytes().to_vec()).unwrap();
434+
let str = String::from_utf8(CStr::from_ptr(buf as *const _).to_bytes().to_vec()).unwrap();
435435
ffi::CRYPTO_free(buf as *mut c_void);
436436
str
437437
}

openssl/src/ssl/error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,24 @@ pub enum OpensslError {
117117

118118
fn get_lib(err: c_ulong) -> String {
119119
unsafe {
120-
let bytes = CStr::from_ptr(ffi::ERR_lib_error_string(err)).to_bytes().to_vec();
120+
let cstr = ffi::ERR_lib_error_string(err);
121+
let bytes = CStr::from_ptr(cstr as *const _).to_bytes().to_vec();
121122
String::from_utf8(bytes).unwrap()
122123
}
123124
}
124125

125126
fn get_func(err: c_ulong) -> String {
126127
unsafe {
127-
let bytes = CStr::from_ptr(ffi::ERR_func_error_string(err)).to_bytes().to_vec();
128+
let cstr = ffi::ERR_func_error_string(err);
129+
let bytes = CStr::from_ptr(cstr as *const _).to_bytes().to_vec();
128130
String::from_utf8(bytes).unwrap()
129131
}
130132
}
131133

132134
fn get_reason(err: c_ulong) -> String {
133135
unsafe {
134-
let bytes = CStr::from_ptr(ffi::ERR_reason_error_string(err)).to_bytes().to_vec();
136+
let cstr = ffi::ERR_reason_error_string(err);
137+
let bytes = CStr::from_ptr(cstr as *const _).to_bytes().to_vec();
135138
String::from_utf8(bytes).unwrap()
136139
}
137140
}

openssl/src/ssl/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl SslContext {
533533
let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
534534
wrap_ssl_result(
535535
unsafe {
536-
ffi::SSL_CTX_load_verify_locations(self.ctx, file.as_ptr(), ptr::null())
536+
ffi::SSL_CTX_load_verify_locations(self.ctx, file.as_ptr() as *const _, ptr::null())
537537
})
538538
}
539539

@@ -543,7 +543,7 @@ impl SslContext {
543543
let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
544544
wrap_ssl_result(
545545
unsafe {
546-
ffi::SSL_CTX_use_certificate_file(self.ctx, file.as_ptr(), file_type as c_int)
546+
ffi::SSL_CTX_use_certificate_file(self.ctx, file.as_ptr() as *const _, file_type as c_int)
547547
})
548548
}
549549

@@ -553,7 +553,7 @@ impl SslContext {
553553
let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
554554
wrap_ssl_result(
555555
unsafe {
556-
ffi::SSL_CTX_use_certificate_chain_file(self.ctx, file.as_ptr(), file_type as c_int)
556+
ffi::SSL_CTX_use_certificate_chain_file(self.ctx, file.as_ptr() as *const _, file_type as c_int)
557557
})
558558
}
559559

@@ -580,7 +580,7 @@ impl SslContext {
580580
let file = CString::new(file.as_ref().as_os_str().to_str().expect("invalid utf8")).unwrap();
581581
wrap_ssl_result(
582582
unsafe {
583-
ffi::SSL_CTX_use_PrivateKey_file(self.ctx, file.as_ptr(), file_type as c_int)
583+
ffi::SSL_CTX_use_PrivateKey_file(self.ctx, file.as_ptr() as *const _, file_type as c_int)
584584
})
585585
}
586586

@@ -604,7 +604,7 @@ impl SslContext {
604604
wrap_ssl_result(
605605
unsafe {
606606
let cipher_list = CString::new(cipher_list).unwrap();
607-
ffi::SSL_CTX_set_cipher_list(self.ctx, cipher_list.as_ptr())
607+
ffi::SSL_CTX_set_cipher_list(self.ctx, cipher_list.as_ptr() as *const _)
608608
})
609609
}
610610

@@ -791,7 +791,7 @@ impl Ssl {
791791
pub fn state_string(&self) -> &'static str {
792792
let state = unsafe {
793793
let ptr = ffi::SSL_state_string(self.ssl);
794-
CStr::from_ptr(ptr)
794+
CStr::from_ptr(ptr as *const _)
795795
};
796796

797797
str::from_utf8(state.to_bytes()).unwrap()
@@ -800,7 +800,7 @@ impl Ssl {
800800
pub fn state_string_long(&self) -> &'static str {
801801
let state = unsafe {
802802
let ptr = ffi::SSL_state_string_long(self.ssl);
803-
CStr::from_ptr(ptr)
803+
CStr::from_ptr(ptr as *const _)
804804
};
805805

806806
str::from_utf8(state.to_bytes()).unwrap()
@@ -809,7 +809,7 @@ impl Ssl {
809809
/// Sets the host name to be used with SNI (Server Name Indication).
810810
pub fn set_hostname(&self, hostname: &str) -> Result<(), SslError> {
811811
let cstr = CString::new(hostname).unwrap();
812-
let ret = unsafe { ffi_extras::SSL_set_tlsext_host_name(self.ssl, cstr.as_ptr()) };
812+
let ret = unsafe { ffi_extras::SSL_set_tlsext_host_name(self.ssl, cstr.as_ptr() as *const _) };
813813

814814
// For this case, 0 indicates failure.
815815
if ret == 0 {
@@ -897,7 +897,7 @@ impl Ssl {
897897

898898
let meth = unsafe { ffi::SSL_COMP_get_name(ptr) };
899899
let s = unsafe {
900-
String::from_utf8(CStr::from_ptr(meth).to_bytes().to_vec()).unwrap()
900+
String::from_utf8(CStr::from_ptr(meth as *const _).to_bytes().to_vec()).unwrap()
901901
};
902902

903903
Some(s)

openssl/src/x509/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Deref for SslString {
5050
impl SslString {
5151
unsafe fn new(buf: *const c_char) -> SslString {
5252
SslString {
53-
s: str::from_utf8(CStr::from_ptr(buf).to_bytes()).unwrap()
53+
s: str::from_utf8(CStr::from_ptr(buf as *const _).to_bytes()).unwrap()
5454
}
5555
}
5656
}
@@ -284,8 +284,8 @@ impl X509Generator {
284284
lift_ssl!(unsafe {
285285
let key = CString::new(key.as_bytes()).unwrap();
286286
let value = CString::new(value.as_bytes()).unwrap();
287-
ffi::X509_NAME_add_entry_by_txt(name, key.as_ptr(), ffi::MBSTRING_UTF8,
288-
value.as_ptr(), value_len, -1, 0)
287+
ffi::X509_NAME_add_entry_by_txt(name, key.as_ptr() as *const _, ffi::MBSTRING_UTF8,
288+
value.as_ptr() as *const _, value_len, -1, 0)
289289
})
290290
}
291291

0 commit comments

Comments
 (0)