about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-04-26 15:43:01 +0200
committerptitSeb <sebastien.chev@gmail.com>2025-04-26 15:43:01 +0200
commitc849178bf8649b900f48b44dbe1b7c71e35fb69a (patch)
tree4e3a30c4519fd76662f884bd285e89b89a126d20 /src
parentff4ae1f4d83d49b1071506146ca403316d914b61 (diff)
downloadbox64-c849178bf8649b900f48b44dbe1b7c71e35fb69a.tar.gz
box64-c849178bf8649b900f48b44dbe1b7c71e35fb69a.zip
[WRAPPER] Fixed some potential sagfault on my_backtrace wrapped function
Diffstat (limited to 'src')
-rw-r--r--src/wrapped/wrappedlibc.c6
1 files changed, 6 insertions, 0 deletions
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