diff options
| author | bors <bors@rust-lang.org> | 2018-08-18 17:15:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-18 17:15:31 +0000 |
| commit | f0341412ed4b7c39003f2bf409b183d7ce066814 (patch) | |
| tree | 7f304d12a4d53986a36dc3f826d95ca323f43f51 /src/libstd | |
| parent | a3ad012e2d33680d40b325258c0da532d0a884f3 (diff) | |
| parent | f4e8d57b6ad6f599de54c020ba185db83cb011a3 (diff) | |
| download | rust-f0341412ed4b7c39003f2bf409b183d7ce066814.tar.gz rust-f0341412ed4b7c39003f2bf409b183d7ce066814.zip | |
Auto merge of #53436 - cuviper:trace_fn-stop, r=alexcrichton
std: stop backtracing when the frames are full This is a defensive measure to mitigate the infinite unwind loop seen in #53372. That case will still repeatedly unwind `__rust_try`, but now it will at least stop when `cx.frames` is full. r? @alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/cloudabi/backtrace.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sys/redox/backtrace/tracing.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sys/unix/backtrace/tracing/gcc_s.rs | 18 |
3 files changed, 30 insertions, 24 deletions
diff --git a/src/libstd/sys/cloudabi/backtrace.rs b/src/libstd/sys/cloudabi/backtrace.rs index 1b970187558..2c43b5937ce 100644 --- a/src/libstd/sys/cloudabi/backtrace.rs +++ b/src/libstd/sys/cloudabi/backtrace.rs @@ -64,6 +64,10 @@ extern "C" fn trace_fn( arg: *mut libc::c_void, ) -> uw::_Unwind_Reason_Code { let cx = unsafe { &mut *(arg as *mut Context) }; + if cx.idx >= cx.frames.len() { + return uw::_URC_NORMAL_STOP; + } + let mut ip_before_insn = 0; let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void }; if !ip.is_null() && ip_before_insn == 0 { @@ -73,14 +77,12 @@ extern "C" fn trace_fn( } let symaddr = unsafe { uw::_Unwind_FindEnclosingFunction(ip) }; - if cx.idx < cx.frames.len() { - cx.frames[cx.idx] = Frame { - symbol_addr: symaddr as *mut u8, - exact_position: ip as *mut u8, - inline_context: 0, - }; - cx.idx += 1; - } + cx.frames[cx.idx] = Frame { + symbol_addr: symaddr as *mut u8, + exact_position: ip as *mut u8, + inline_context: 0, + }; + cx.idx += 1; uw::_URC_NO_REASON } diff --git a/src/libstd/sys/redox/backtrace/tracing.rs b/src/libstd/sys/redox/backtrace/tracing.rs index bb70ca36037..c0414b78f8d 100644 --- a/src/libstd/sys/redox/backtrace/tracing.rs +++ b/src/libstd/sys/redox/backtrace/tracing.rs @@ -68,6 +68,10 @@ pub fn unwind_backtrace(frames: &mut [Frame]) extern fn trace_fn(ctx: *mut uw::_Unwind_Context, arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code { let cx = unsafe { &mut *(arg as *mut Context) }; + if cx.idx >= cx.frames.len() { + return uw::_URC_NORMAL_STOP; + } + let mut ip_before_insn = 0; let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void @@ -94,14 +98,12 @@ extern fn trace_fn(ctx: *mut uw::_Unwind_Context, unsafe { uw::_Unwind_FindEnclosingFunction(ip) } }; - if cx.idx < cx.frames.len() { - cx.frames[cx.idx] = Frame { - symbol_addr: symaddr as *mut u8, - exact_position: ip as *mut u8, - inline_context: 0, - }; - cx.idx += 1; - } + cx.frames[cx.idx] = Frame { + symbol_addr: symaddr as *mut u8, + exact_position: ip as *mut u8, + inline_context: 0, + }; + cx.idx += 1; uw::_URC_NO_REASON } diff --git a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs index 1b92fc0e6ad..6e841568679 100644 --- a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs +++ b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs @@ -68,6 +68,10 @@ pub fn unwind_backtrace(frames: &mut [Frame]) extern fn trace_fn(ctx: *mut uw::_Unwind_Context, arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code { let cx = unsafe { &mut *(arg as *mut Context) }; + if cx.idx >= cx.frames.len() { + return uw::_URC_NORMAL_STOP; + } + let mut ip_before_insn = 0; let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void @@ -94,14 +98,12 @@ extern fn trace_fn(ctx: *mut uw::_Unwind_Context, unsafe { uw::_Unwind_FindEnclosingFunction(ip) } }; - if cx.idx < cx.frames.len() { - cx.frames[cx.idx] = Frame { - symbol_addr: symaddr as *mut u8, - exact_position: ip as *mut u8, - inline_context: 0, - }; - cx.idx += 1; - } + cx.frames[cx.idx] = Frame { + symbol_addr: symaddr as *mut u8, + exact_position: ip as *mut u8, + inline_context: 0, + }; + cx.idx += 1; uw::_URC_NO_REASON } |
