NagyD / SDLPoP

An open-source port of Prince of Persia, based on the disassembly of the DOS version.
GNU General Public License v3.0
1.1k stars 140 forks source link

Segfault due to implicit strdup #315

Closed vlasta-labsky closed 4 months ago

vlasta-labsky commented 4 months ago

I found a bug that causes crash right on startup, trying load sounds.

Backtrace of the crash: #0 __strlen_sse2 () at ../sysdeps/x86_64/multiarch/strlen-vec.S:126 #1 0x00007ffff7b24d31 in __vfprintf_internal (s=s@entry=0x7fffffffda80, format=format@entry=0x5555555ba56e "%s/music/%s.ogg", ap=ap@entry=0x7fffffffdc00, mode_flags=mode_flags@entry=0) at ./stdio-common/vfprintf-internal.c:1517 #2 0x00007ffff7b3649a in __vsnprintf_internal (string=0x7fffffffddc0 "/music/_absence", maxlen=<optimized out>, format=0x5555555ba56e "%s/music/%s.ogg", args=args@entry=0x7fffffffdc00, mode_flags=mode_flags@entry=0) at ./libio/vsnprintf.c:114 #3 0x00007ffff7b0e856 in __GI___snprintf (s=<optimized out>, maxlen=<optimized out>, format=<optimized out>) at ./stdio-common/snprintf.c:31 #4 0x000055555558be0b in load_sound (index=24) at /home/vlastik/Stažené/SDLPoP/src/seg009.c:2261 #5 0x000055555556e194 in load_sounds (first=0, last=43) at /home/vlastik/Stažené/SDLPoP/src/seg000.c:1039 #6 0x0000555555570aaf in load_all_sounds () at /home/vlastik/Stažené/SDLPoP/src/seg000.c:2190 #7 0x000055555556b950 in init_game_main () at /home/vlastik/Stažené/SDLPoP/src/seg000.c:178 #8 0x000055555556b835 in pop_main () at /home/vlastik/Stažené/SDLPoP/src/seg000.c:149 #9 0x000055555556b475 in main (argc=1, argv=0x7fffffffe128) at /home/vlastik/Stažené/SDLPoP/src/main.c:34

It is caused by implicit declarations used by compiler - strdup and strnlen.

I've made a quick fix, will link a PR.