zed.0xff.me

radare2 0.8.x unnecessary memory zeroing fix

radare2 bug

the bug only appears when debugging 32-bit binary on a 64-bit host

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
diff -r e96275c214b5 libr/io/p/io_ptrace.c
--- a/libr/io/p/io_ptrace.c        Mon Oct 24 04:35:42 2011 +0200
+++ b/libr/io/p/io_ptrace.c        Mon Oct 24 16:48:31 2011 +0300
@@ -34,9 +34,11 @@
 #if __OpenBSD__ || __KFBSD__
 #define debug_read_raw(x,y) ptrace(PTRACE_PEEKTEXT, (pid_t)(x), (caddr_t)(y), 0)
 #define debug_write_raw(x,y,z) ptrace(PTRACE_POKEDATA, (pid_t)(x), (caddr_t)(y), (int)(size_t)(z))
+typedef int ptrace_word;   // int ptrace(int request, pid_t pid, caddr_t addr, int data);
 #else
 #define debug_read_raw(x,y) ptrace(PTRACE_PEEKTEXT, x, y, 0)
 #define debug_write_raw(x,y,z) ptrace(PTRACE_POKEDATA, x, y, z)
+typedef void* ptrace_word; // long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
 #endif
 
 static int debug_os_read_at(int pid, ut32 *buf, int sz, ut64 addr) {
@@ -63,10 +65,11 @@
 }
 
 static int ptrace_write_at(int pid, const ut8 *pbuf, int sz, ut64 addr) {
-        ut32 *buf = (ut32*)pbuf;
-        ut32 words = sz / sizeof (ut32);
-        ut32 last = sz % sizeof (ut32);
-        ut32 x, lr, *at = (ut32*)(size_t)addr;
+        ptrace_word *buf = (ptrace_word*)pbuf;
+        ut32 words = sz / sizeof (ptrace_word);
+        ut32 last = sz % sizeof (ptrace_word);
+        ut32 x, *at = (ptrace_word*)(size_t)addr;
+        ptrace_word lr;
         if (sz<1 || addr==UT64_MAX)
                 return -1;
         for (x=0; x<words; x++)

Post a comment


(lesstile enabled - surround code blocks with ---)