2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-01 01:25:38 +03:00

Fix and optimize file extension checks (#317)

Optimize file extension checks
This commit is contained in:
In-line 2017-01-21 23:00:50 +04:00 committed by theAsmodai
parent 47964c847b
commit fb3ec088e1
2 changed files with 65 additions and 3 deletions

View File

@ -5204,6 +5204,10 @@ void SV_CreateGenericResources(void)
data = COM_Parse(data);
if (Q_strlen(com_token) <= 0)
break;
#ifdef REHLDS_FIXES
char *com_token_extension = Q_strrchr(com_token, '.');
bool successful = false;
#endif
if (Q_strstr(com_token, ".."))
Con_Printf("Can't precache resource with invalid relative path %s\n", com_token);
@ -5211,6 +5215,32 @@ void SV_CreateGenericResources(void)
Con_Printf("Can't precache resource with absolute path %s\n", com_token);
else if (Q_strstr(com_token, "\\"))
Con_Printf("Can't precache resource with invalid relative path %s\n", com_token);
#ifdef REHLDS_FIXES
else if(com_token_extension)
{
if (Q_strcmp(com_token_extension, ".cfg") == 0)
Con_Printf("Can't precache .cfg files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".lst") == 0)
Con_Printf("Can't precache .lst files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".exe") == 0)
Con_Printf("Can't precache .exe files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".vbs") == 0)
Con_Printf("Can't precache .vbs files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".com") == 0)
Con_Printf("Can't precache .com files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".bat") == 0)
Con_Printf("Can't precache .bat files: %s\n", com_token);
else if (Q_strcmp(com_token_extension, ".dll") == 0)
Con_Printf("Can't precache .dll files: %s\n", com_token);
else
successful = true;
}
else
successful = true;
if(successful)
#else
else if (Q_strstr(com_token, ".cfg"))
Con_Printf("Can't precache .cfg files: %s\n", com_token);
else if (Q_strstr(com_token, ".lst"))
@ -5226,6 +5256,7 @@ void SV_CreateGenericResources(void)
else if (Q_strstr(com_token, ".dll"))
Con_Printf("Can't precache .dll files: %s\n", com_token);
else
#endif
{
// In fixed version of PrecacheGeneric we don't need local copy
#ifdef REHLDS_FIXES
@ -7250,6 +7281,7 @@ qboolean IsSafeFileToDownload(const char *filename)
{
char *first;
char *last;
char lwrfilename[MAX_PATH];
if (!filename)
@ -7271,7 +7303,11 @@ qboolean IsSafeFileToDownload(const char *filename)
Q_strlwr(lwrfilename);
first = Q_strchr(lwrfilename, '.');
#ifdef REHLDS_FIXES
last = Q_strrchr(first, '.');
#else
last = Q_strrchr(lwrfilename, '.');
#endif
if (lwrfilename[0] == '/'
|| Q_strstr(lwrfilename, "\\")
@ -7281,6 +7317,23 @@ qboolean IsSafeFileToDownload(const char *filename)
|| first != last
|| !first
|| Q_strlen(first) != 4
|| Q_strstr(lwrfilename, "halflife.wad")
|| Q_strstr(lwrfilename, "pak0.pak")
|| Q_strstr(lwrfilename, "xeno.wad")
#ifdef REHLDS_FIXES
|| Q_strcmp(first, ".cfg") == 0
|| Q_strcmp(first, ".lst") == 0
|| Q_strcmp(first, ".exe") == 0
|| Q_strcmp(first, ".vbs") == 0
|| Q_strcmp(first, ".com") == 0
|| Q_strcmp(first, ".bat") == 0
|| Q_strcmp(first, ".dll") == 0
|| Q_strcmp(first, ".ini") == 0
|| Q_strcmp(first, ".log") == 0
// || Q_strcmp(lwrfilename, ".so") == 0 // Extension length must be 4 to get here
// || Q_strcmp(lwrfilename, ".dylib") == 0
|| Q_strcmp(first, ".sys") == 0)
#else
|| Q_strstr(lwrfilename, ".cfg")
|| Q_strstr(lwrfilename, ".lst")
|| Q_strstr(lwrfilename, ".exe")
@ -7290,12 +7343,10 @@ qboolean IsSafeFileToDownload(const char *filename)
|| Q_strstr(lwrfilename, ".dll")
|| Q_strstr(lwrfilename, ".ini")
|| Q_strstr(lwrfilename, ".log")
|| Q_strstr(lwrfilename, "halflife.wad")
|| Q_strstr(lwrfilename, "pak0.pak")
|| Q_strstr(lwrfilename, "xeno.wad")
|| Q_strstr(lwrfilename, ".so")
|| Q_strstr(lwrfilename, ".dylib")
|| Q_strstr(lwrfilename, ".sys"))
#endif
{
return FALSE;
}

View File

@ -941,11 +941,22 @@ void LoadEntityDLLs(const char *szBaseDir)
Q_strncpy(szValue, com_argv[index + 1], sizeof(szValue) - 1);
szValue[sizeof(szValue) - 1] = 0;
}
#ifdef REHLDS_FIXES
char *value_extension = Q_strrchr(szValue, '.');
#ifdef _WIN32
if (value_extension && Q_strcmp(value_extension, ".dll") == 0)
#else // _WIN32
if (value_extension && Q_strcmp(value_extension, ".so") == 0)
#endif // _WIN32
#else // REHLDS_FIXES
#ifdef _WIN32
if (Q_strstr(szValue, ".dll"))
#else // _WIN32
if (Q_strstr(szValue, ".so"))
#endif // _WIN32
#endif // REHLDS_FIXES
{
FS_GetLocalPath(szValue, szDllFilename, sizeof(szDllFilename));
Con_DPrintf("\nAdding: %s/%s\n", szGameDir, szValue);