From c849178bf8649b900f48b44dbe1b7c71e35fb69a Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 26 Apr 2025 15:43:01 +0200 Subject: [WRAPPER] Fixed some potential sagfault on my_backtrace wrapped function --- src/wrapped/wrappedlibc.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 2b54cd7e..58ecd5b4 100644 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -3499,6 +3499,10 @@ EXPORT int my_backtrace(x64emu_t* emu, void** buffer, int size) dwarf_unwind_t *unwind = init_dwarf_unwind_registers(emu); int idx = 0; char success = 0; + if(!(getProtection_fast(R_RSP)&PROT_READ)) + return 0; + if(!(getProtection_fast((uintptr_t)buffer)&PROT_READ)) + return 0; uintptr_t addr = *(uintptr_t*)R_RSP; buffer[0] = (void*)addr; while (++idx < size) { @@ -3509,6 +3513,8 @@ EXPORT int my_backtrace(x64emu_t* emu, void** buffer, int size) success = 2; // See elfdwarf_private.c for the register mapping unwind->regs[7] = unwind->regs[6]; // mov rsp, rbp + if(!(getProtection_fast(unwind->regs[7])&PROT_READ)) + return idx-1; unwind->regs[6] = *(uint64_t*)unwind->regs[7]; // pop rbp unwind->regs[7] += 8; ret_addr = *(uint64_t*)unwind->regs[7]; // ret -- cgit 1.4.1