libretro / px68k-libretro

Portable SHARP X68000 Emulator for Libretro
http://hissorii.blog45.fc2.com
GNU General Public License v2.0
47 stars 42 forks source link

Fix wrong strncpy() size calculation of win32api/dosio.c #67

Closed hchonan closed 6 years ago

hchonan commented 6 years ago

strncpy() max size calculation on win32api/dosio.c is wrong.

For example in case curpath is ".//keropi/" (10 byte length), strncpy() append filename only 10byte. It means reading BIOS ROM "iplrom.dat" will be success ( curpath ".//keropi/iplrom.dat" will be generated ) however, reading BIOS ROM "iplrom30.dat" will be fail ( curpath ".//keropi/iplrom30.d" will be generated ).

And if length of curpath is longher than 0.5*(MAX_PATH+32) byte, strncpy() shall run over curpath buffer. strncpy() max size must be smaller than MAX_PATH + 32 - (curfilep - curpath). Considering 32 byte as safe margin, correct max size will be MAX_PATH - (curfilep - curpath).