keystone-engine / keystone

Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings
http://www.keystone-engine.org
GNU General Public License v2.0
2.27k stars 454 forks source link

Segmentation fault when assembling multiple section #368

Open eternalklaus opened 6 years ago

eternalklaus commented 6 years ago

I got segmentation fault on latest keystone, When I tried to assemble the assembly file consist of multiple sections

I wrote test.py using example code of keystone.

f = open('ex.s','r')
CODE = f.read()

try:
    # Initialize engine in X86-32bit mode
    ks = Ks(KS_ARCH_X86, KS_MODE_32)
    ks.syntax = KS_OPT_SYNTAX_ATT # ATT신텍스
    encoding, count = ks.asm(CODE)
    print("%s (number of statements: %u)" %(encoding, count))
except KsError as e:
    print("ERROR: %s" %e)

I executed it, and Segmentation fault occured.

$ python tmp.py 
Segmentation fault (core dumped)

Here is ex.s, the assembly file that I tried to assemble. I think there's nothing weird on this assembly file.

.global main
.text
main:
 pop %eax
.rodata
.byte 0x99, 0x99

What's happening on ketstone? Why segfault happens?

PS1. Here is the experiment environment

PS2. I think #204 is related to this issue.

eternalklaus commented 6 years ago

core.zip In case of you need, here is core dump file on the incident.