endrazine / wcc

The Witchcraft Compiler Collection
Other
1.84k stars 107 forks source link

wsh segfaulting on startup #5

Closed twilight-sparkle-irl closed 8 years ago

twilight-sparkle-irl commented 8 years ago

$ wsh [SIGSEGV] Read 000000000017 (address not mapped to object) 000042009d64 wsh(scan_sections+0x91) 000042009e7d wsh(shdr_callback+0x60) 7fd279ade6a4 /usr/lib/libc.so.6(dl_iterate_phdr+0xf4) 00004200cdc1 wsh(reload_elfs+0x2f8) 00004201deb9 wsh(main+0x67) 7fd2799e2741 /usr/lib/libc.so.6(__libc_start_main+0xf1) 000042007979 wsh(_start+0x29) [1] 18835 segmentation fault wsh

% uname -a Linux hostname 4.6.3-1-ARCH #1 SMP PREEMPT Fri Jun 24 21:19:13 CEST 2016 x86_64 GNU/Linux

endrazine commented 8 years ago

Hi no-boot-device, Thanks for your bug report. This is an interresting case !

[SIGSEGV] Read 000000000017 (address not mapped to object)

This tells us that the bug is a Segmentation Fault due to a read operation at address 0x17, which is not mapped. That's a null pointer.

From the backtrace, it happened in function scan_sections() from wsh. What is unexpected is that wsh went that far given that it has been invoked witout a binary to analyse in the command line. On my machine, the same command gives :

jonathan@blackbox:~$ wsh
ERROR: No binary to execute
jonathan@blackbox:~$ 

I have modified wsh_getopt() to assert at least one argument has been given to wsh. Here is what it new looks like:

jonathan@blackbox:~/wcc$ ./bin/wsh        
ERROR: not enough arguments !
Try --help for help.
jonathan@blackbox:~/wcc$ 

That should resolve the bug. Let me know if this works on your machine too :)

Cheers,

j-

Silur commented 7 years ago

however the exact same backtrace is shown even if I pass an executable to it, tried it with ./ and fullt-path notation

$ wsh /tmp/testme
[SIGSEGV]       Read    000000000017        (address not mapped to object)
        000042009ce4    wsh(scan_sections+0x91)
        000042009dfd    wsh(shdr_callback+0x60)
        7ff7beab25a4    /usr/lib/libc.so.6(dl_iterate_phdr+0xf4)
        00004200cd41    wsh(reload_elfs+0x2f8)
        00004201de40    wsh(main+0x67)
        7ff7be9b4291    /usr/lib/libc.so.6(__libc_start_main+0xf1)
        0000420078fa    wsh(_start+0x2a)
Segmentation fault

Naturally I have the latest master