DanielT / NitroHack

A fork of NetHack 3.4.3
nitrohack.org
21 stars 2 forks source link

Crash when throwing or dropping objects while engulfed #23

Open tung opened 12 years ago

tung commented 12 years ago

I get a segfault when dropping a scroll of scare monster while engulfed in an air elemental. To reproduce: get in wizmode, #levelchange to something that won't die instantly, summon an air elemental, get engulfed, wish up a scroll of scare monster, drop the scroll, segfault occurs.

I ran NitroHack in gdb and got this backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x0023d1b9 in examine_object () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
(gdb) backtrace
#0  0x0023d1b9 in examine_object () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
#1  0x001d626b in update_location () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
#2  0x0013c154 in pre_move_tasks () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
#3  0x0013c42e in command_input () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
#4  0x0013c5b1 in nh_command () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack.so
#5  0x003d91b9 in nhnet_command () from /home/tung/Install/nitrohack/nitrohack-data/libnitrohack_client.so
#6  0x0805d892 in commandloop ()
#7  0x0805dc70 in rungame ()
#8  0x0804aafd in mainmenu ()
#9  0x0804ac0d in main ()
tung commented 12 years ago

This crash actually occurs when throwing or dropping any object while engulfed. The problem is the new update_location() function in invent.c, which uses otmp->nexthere to iterate over objects on the floor and in the inventory of an engulfing monster, but the latter needs to use otmp->nobj instead.

Fix with context in my experimental branch, as usual.