Check for truncated paths in Sys_LoadDll

Check for truncated paths which could allow loading a library with
a non-standard extension. Also provides a better message for why a
valid library with a long path would fail to load.
This commit is contained in:
Zack Middleton 2017-05-24 09:51:48 -05:00
parent 05858d30e8
commit 70af7e673f

View file

@ -513,16 +513,25 @@ void *Sys_LoadDll(const char *name, qboolean useSystemLib)
{
const char *topDir;
char libPath[MAX_OSPATH];
int len;
topDir = Sys_BinaryPath();
if(!*topDir)
topDir = ".";
len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name);
if(len < sizeof(libPath))
{
Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, topDir);
Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name);
dllhandle = Sys_LoadLibrary(libPath);
}
else
{
Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, topDir);
}
if(!(dllhandle = Sys_LoadLibrary(libPath)))
if(!dllhandle)
{
const char *basePath = Cvar_VariableString("fs_basepath");
@ -530,11 +539,18 @@ void *Sys_LoadDll(const char *name, qboolean useSystemLib)
basePath = ".";
if(FS_FilenameCompare(topDir, basePath))
{
len = Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name);
if(len < sizeof(libPath))
{
Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, basePath);
Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name);
dllhandle = Sys_LoadLibrary(libPath);
}
else
{
Com_Printf("Skipping trying to load \"%s\" from \"%s\", file name is too long.\n", name, basePath);
}
}
if(!dllhandle)
Com_Printf("Loading \"%s\" failed\n", name);