UDIS86: fixed crash caused by keeping `ud_t` structure on smalltalk heap
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 29 Aug 2018 21:32:19 +0100
changeset 50 7f439240d923
parent 49 704b049b9aa2
child 51 bac3aa0c73ef
UDIS86: fixed crash caused by keeping `ud_t` structure on smalltalk heap ...and this the structure may move. Thisx resulted on hard-to-debug heap corruptions because `ud_t.asm_buf` is initializad to a pointer to `ud_t.asm_buf_int`. Therefore when the bytearray moved, the pointer become invalid and subsequent call to `ud_disassemble()` smashed whatever object happened to be where the bytearray were. The fix is straigtforward, use `ExternalBytes`! Sigh.
udis86sx/UDIS86.st
--- a/udis86sx/UDIS86.st	Thu Aug 16 14:10:06 2018 +0100
+++ b/udis86sx/UDIS86.st	Wed Aug 29 21:32:19 2018 +0100
@@ -43,7 +43,7 @@
 
 #include <udis86.h>
 
-#define ud ((ud_t*)(&__byteArrayVal( __INST(handle) )))
+#define ud ((ud_t*)(__externalAddressVal( __INST(handle) )))
 
 %}
 ! !
@@ -317,7 +317,7 @@
 %{
     handleSize = __MKSMALLINT( sizeof( ud_t ) );
 %}.
-    handle := ByteArray new: handleSize.
+    handle := ExternalBytes unprotectedNew: handleSize.
 %{
     ud_init( ud );
     ud_set_syntax ( ud, UD_SYN_INTEL );