diff options
| author | bors <bors@rust-lang.org> | 2017-09-20 14:50:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-09-20 14:50:31 +0000 |
| commit | 01c65cb15ac57bfdc91613a4f6032ecc76c402a3 (patch) | |
| tree | 3622c88ffe76513d86657eab0f485d6f1d789a3e /src/libstd/sys_common | |
| parent | 4cdb36262b93390c8733a1ce44665619d9348981 (diff) | |
| parent | 15887d786ba05a84f2fc5e7036cae88b91291c6c (diff) | |
| download | rust-01c65cb15ac57bfdc91613a4f6032ecc76c402a3.tar.gz rust-01c65cb15ac57bfdc91613a4f6032ecc76c402a3.zip | |
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
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/gnu/libbacktrace.rs | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/libstd/sys_common/gnu/libbacktrace.rs b/src/libstd/sys_common/gnu/libbacktrace.rs index 14c0e8699bc..016c840d154 100644 --- a/src/libstd/sys_common/gnu/libbacktrace.rs +++ b/src/libstd/sys_common/gnu/libbacktrace.rs @@ -30,6 +30,12 @@ where F: FnMut(&[u8], libc::c_int) -> io::Result<()> let ret; let fileline_count = { 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 fileline_addr = &mut fileline_win as *mut &mut [FileLine]; ret = unsafe { @@ -62,23 +68,25 @@ pub fn resolve_symname<F>(frame: Frame, let symname = { let state = unsafe { init_state() }; 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 } else { - 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 - } else { - unsafe { - CStr::from_ptr(data).to_str().ok() - } + unsafe { + CStr::from_ptr(data).to_str().ok() } } }; |
