mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-24 22:44:26 +00:00
Auto merge of #44525 - aidanhs:aphs-no-null-deref, r=alexcrichton
Correctly bubble up errors from libbacktrace Previously the first part of this code didn't check for a null pointer and blindly passed it back down, causing a segfault if libbacktrace failed to initialise. I've changed this to check and bubble up the error if relevant. Suggested diff view: https://github.com/rust-lang/rust/pull/44525/files?w=1
This commit is contained in:
commit
01c65cb15a
@ -30,6 +30,12 @@ where F: FnMut(&[u8], libc::c_int) -> io::Result<()>
|
|||||||
let ret;
|
let ret;
|
||||||
let fileline_count = {
|
let fileline_count = {
|
||||||
let state = unsafe { init_state() };
|
let state = unsafe { init_state() };
|
||||||
|
if state.is_null() {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
"failed to allocate libbacktrace state")
|
||||||
|
)
|
||||||
|
}
|
||||||
let mut fileline_win: &mut [FileLine] = &mut fileline_buf;
|
let mut fileline_win: &mut [FileLine] = &mut fileline_buf;
|
||||||
let fileline_addr = &mut fileline_win as *mut &mut [FileLine];
|
let fileline_addr = &mut fileline_win as *mut &mut [FileLine];
|
||||||
ret = unsafe {
|
ret = unsafe {
|
||||||
@ -62,23 +68,25 @@ pub fn resolve_symname<F>(frame: Frame,
|
|||||||
let symname = {
|
let symname = {
|
||||||
let state = unsafe { init_state() };
|
let state = unsafe { init_state() };
|
||||||
if state.is_null() {
|
if state.is_null() {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
"failed to allocate libbacktrace state")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let mut data = ptr::null();
|
||||||
|
let data_addr = &mut data as *mut *const libc::c_char;
|
||||||
|
let ret = unsafe {
|
||||||
|
backtrace_syminfo(state,
|
||||||
|
frame.symbol_addr as libc::uintptr_t,
|
||||||
|
syminfo_cb,
|
||||||
|
error_cb,
|
||||||
|
data_addr as *mut libc::c_void)
|
||||||
|
};
|
||||||
|
if ret == 0 || data.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let mut data = ptr::null();
|
unsafe {
|
||||||
let data_addr = &mut data as *mut *const libc::c_char;
|
CStr::from_ptr(data).to_str().ok()
|
||||||
let ret = unsafe {
|
|
||||||
backtrace_syminfo(state,
|
|
||||||
frame.symbol_addr as libc::uintptr_t,
|
|
||||||
syminfo_cb,
|
|
||||||
error_cb,
|
|
||||||
data_addr as *mut libc::c_void)
|
|
||||||
};
|
|
||||||
if ret == 0 || data.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
unsafe {
|
|
||||||
CStr::from_ptr(data).to_str().ok()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user