Engine: findfrompath(fn, where) returns 0 when fn is an empty string
This issue concerns the function findfrompath(fn,where)
in source/build/src/vfs.cpp
, line 280.
If we pass an empty string as filename, the function should return a non-zero value, since the empty string does not exist as a file inside the folder. However, due to a bug, it will return 0 instead.
This code causes the problem:
char *pfn = (char *)Xmalloc(allocsiz);
strcpy(pfn, "./");
strcat(pfn, ffn);
if (buildvfs_exists(pfn))
{
*where = pfn;
Xfree(ffn);
return 0;
}
ffn
is hereby a copy of fn
. ffn
contains an empty string, and the code hence stores the path "./"
inside pfn
.
Of course, this is the current directory, which always exists, hence the function will return 0. There needs to be a special case here that makes the function return -1 if the input fn
is empty.
A concrete instance where this leads to a bug is with RTS file checking in Duke3D. If the RTS filename is empty, i.e. undefined, then the function will return true, and the game will attempt to read the base directory as the RTS file, and produce a strange error in the console.