indigodarkwolf / box16

A fork of the official X16 emulator, converted to C++20 and with a bunch of features tweaked and added.
MIT License
42 stars 19 forks source link

program can segfault the emulator #100

Closed irmen closed 1 year ago

irmen commented 1 year ago

See https://github.com/X16Community/x16-emulator/issues/121 for a very similar problem in x16emu

start box16 LOAD "TEST.PRG" RUN

observe segfault:

(gdb) where
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f83dd1b22d3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007f83dd162a08 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f83dd14b538 in __GI_abort () at abort.c:79
#4  0x00007f83dd49ca6f in __gnu_cxx::__verbose_terminate_handler() ()
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#5  0x00007f83dd4b011c in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#6  0x00007f83dd4b0189 in std::terminate() () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#7  0x00007f83dd4b03ed in __cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*))
    (obj=<optimized out>, tinfo=0x7f83dd672738 <typeinfo for std::filesystem::__cxx11::filesystem_error>, dest=0x7f83dd59c9e0 <std::filesystem::__cxx11::filesystem_error::~filesystem_error()>)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98
#8  0x00007f83dd4a6078 in std::filesystem::absolute(std::filesystem::__cxx11::path const&) (p=filesystem::path "")
    at /usr/src/debug/gcc/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/new_allocator.h:100
#9  0x0000558ea79f6cbc in resolve_path(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) ()
#10 0x0000558ea79f933b in copen(int) ()
#11 0x0000558ea79f2f76 in hypercalls_update()::{lambda()#7}::_FUN() ()
#12 0x0000558ea79f34a2 in hypercalls_process() ()
#13 0x0000558ea79fe483 in emulator_loop() ()
#14 0x0000558ea79dc99c in main ()

the test program basically does a LOAD with a zero-length filename.

Interesting is that if you do box16 -prg TEST.PRG and then type RUN, the emulator doesn't segfault but instead exits cleanly with the pc=$ffff error message.

testprog.zip

indigodarkwolf commented 1 year ago

Should be fixed in 954327c54fa0040764aa222db0b7369300581d57