OpenArena / engine

OpenArena modifications to the ioquake3 engine
http://openarena.ws
GNU General Public License v2.0
211 stars 50 forks source link

Fix crashes when compiled with ASan #55

Open hpoggie opened 5 years ago

hpoggie commented 5 years ago

This fixes https://github.com/OpenArena/engine/issues/54.

Compiling with ASan makes it easier to find memory errors. Previously the game would compile with ASan but immediately crash if run.

sago007 commented 5 years ago

Still crashes for me:

=================================================================
==28650==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fffec0394c0 at pc 0x0000006e0f3e bp 0x7fffec0390f0 sp 0x7fffec0390e8
READ of size 4 at 0x7fffec0394c0 thread T0
    #0 0x6e0f3d in VM_Call /home/poul/programmering/openarena/git-engine/engine/code/qcommon/vm.c:855:16
    #1 0x612254 in Com_Init /home/poul/programmering/openarena/git-engine/engine/code/qcommon/common.c:2819:2
    #2 0x8111d9 in main /home/poul/programmering/openarena/git-engine/engine/code/sys/sys_main.c:645:2
    #3 0x7f686903709a in __libc_start_main /build/glibc-B9XfQf/glibc-2.28/csu/../csu/libc-start.c:308:16
    #4 0x420029 in _start (/bighome/poul/games/openarena-0.8.8/openarena.x86_64_asan+0x420029)

Address 0x7fffec0394c0 is located in stack of thread T0 at offset 0 in frame
    #0 0x610c9f in Com_Init /home/poul/programmering/openarena/git-engine/engine/code/qcommon/common.c:2636

  This frame has 2 object(s):
    [32, 36) 'seed.i' (line 2623)
    [48, 52) 'qport' (line 2638)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /home/poul/programmering/openarena/git-engine/engine/code/qcommon/vm.c:855:16 in VM_Call

Looks like some nasty C variable argument list to me.

hpoggie commented 5 years ago

That's a sketchy thing that the quake vm does. It copies a fixed number of arguments into the vm (12, I think) and then figures out how many it actually needs later. I meant to ignore this by including -fsanitize-blacklist=asan_ignore.txt in Makefile.local.asan but somehow that didn't get committed.