- Fix potential out-of-bounds read in files.c, fix by using new FS_IsExt
- Add capability to load demos with com_protocol suffix, partially applied patches from Simon McVittie - Fix demo loading if protocol number has more digits than 2 - Minor refactoring, replace all occurances of suffix "dm_" with global macro DEMOEXT
This commit is contained in:
parent
fef4d12d68
commit
c0cca7a0a8
6 changed files with 125 additions and 48 deletions
|
@ -941,6 +941,59 @@ qboolean FS_FilenameCompare( const char *s1, const char *s2 ) {
|
|||
return qfalse; // strings are equal
|
||||
}
|
||||
|
||||
/*
|
||||
===========
|
||||
FS_IsExt
|
||||
|
||||
Return qtrue if ext matches file extension filename
|
||||
===========
|
||||
*/
|
||||
|
||||
qboolean FS_IsExt(const char *filename, const char *ext, int namelen)
|
||||
{
|
||||
int extlen;
|
||||
|
||||
extlen = strlen(ext);
|
||||
|
||||
if(extlen > namelen)
|
||||
return qfalse;
|
||||
|
||||
filename += namelen - extlen;
|
||||
|
||||
return !Q_stricmp(filename, ext);
|
||||
}
|
||||
|
||||
/*
|
||||
===========
|
||||
FS_IsDemoExt
|
||||
|
||||
Return qtrue if filename has a demo extension
|
||||
===========
|
||||
*/
|
||||
|
||||
qboolean FS_IsDemoExt(const char *filename, int namelen)
|
||||
{
|
||||
char *ext_test;
|
||||
int index, protocol;
|
||||
|
||||
ext_test = Q_strrchr(filename, '.');
|
||||
if(ext_test && !Q_stricmpn(ext_test + 1, DEMOEXT, ARRAY_LEN(DEMOEXT) - 1))
|
||||
{
|
||||
protocol = atoi(ext_test + ARRAY_LEN(DEMOEXT));
|
||||
|
||||
if(protocol == com_protocol->integer)
|
||||
return qtrue;
|
||||
|
||||
for(index = 0; demo_protocols[index]; index++)
|
||||
{
|
||||
if(demo_protocols[index] == protocol)
|
||||
return qtrue;
|
||||
}
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
===========
|
||||
FS_FOpenFileRead
|
||||
|
@ -962,7 +1015,6 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
|
|||
long hash;
|
||||
FILE *temp;
|
||||
int l;
|
||||
char demoExt[16];
|
||||
|
||||
hash = 0;
|
||||
|
||||
|
@ -1009,7 +1061,6 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
|
|||
Com_Error( ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed\n" );
|
||||
}
|
||||
|
||||
Com_sprintf (demoExt, sizeof(demoExt), ".dm_%d",PROTOCOL_VERSION );
|
||||
// qpaths are not supposed to have a leading slash
|
||||
if ( filename[0] == '/' || filename[0] == '\\' ) {
|
||||
filename++;
|
||||
|
@ -1061,16 +1112,19 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
|
|||
// shaders, txt, arena files by themselves do not count as a reference as
|
||||
// these are loaded from all pk3s
|
||||
// from every pk3 file..
|
||||
l = strlen( filename );
|
||||
if ( !(pak->referenced & FS_GENERAL_REF)) {
|
||||
if ( Q_stricmp(filename + l - 7, ".shader") != 0 &&
|
||||
Q_stricmp(filename + l - 4, ".txt") != 0 &&
|
||||
Q_stricmp(filename + l - 4, ".cfg") != 0 &&
|
||||
Q_stricmp(filename + l - 7, ".config") != 0 &&
|
||||
strstr(filename, "levelshots") == NULL &&
|
||||
Q_stricmp(filename + l - 4, ".bot") != 0 &&
|
||||
Q_stricmp(filename + l - 6, ".arena") != 0 &&
|
||||
Q_stricmp(filename + l - 5, ".menu") != 0) {
|
||||
l = strlen(filename);
|
||||
|
||||
if (!(pak->referenced & FS_GENERAL_REF))
|
||||
{
|
||||
if(!FS_IsExt(filename, ".shader", l) &&
|
||||
!FS_IsExt(filename, ".txt", l) &&
|
||||
!FS_IsExt(filename, ".cfg", l) &&
|
||||
!FS_IsExt(filename, ".config", l) &&
|
||||
!FS_IsExt(filename, ".bot", l) &&
|
||||
!FS_IsExt(filename, ".arena", l) &&
|
||||
!FS_IsExt(filename, ".menu", l) &&
|
||||
!strstr(filename, "levelshots"))
|
||||
{
|
||||
pak->referenced |= FS_GENERAL_REF;
|
||||
}
|
||||
}
|
||||
|
@ -1121,13 +1175,14 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
|
|||
// this test can make the search fail although the file is in the directory
|
||||
// I had the problem on https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=8
|
||||
// turned out I used FS_FileExists instead
|
||||
if ( fs_numServerPaks ) {
|
||||
|
||||
if ( Q_stricmp( filename + l - 4, ".cfg" ) // for config files
|
||||
&& Q_stricmp( filename + l - 5, ".menu" ) // menu files
|
||||
&& Q_stricmp( filename + l - 5, ".game" ) // menu files
|
||||
&& Q_stricmp( filename + l - strlen(demoExt), demoExt ) // menu files
|
||||
&& Q_stricmp( filename + l - 4, ".dat" ) ) { // for journal files
|
||||
if(fs_numServerPaks)
|
||||
{
|
||||
if(!FS_IsExt(filename, ".cfg", l) && // for config files
|
||||
!FS_IsExt(filename, ".menu", l) && // menu files
|
||||
!FS_IsExt(filename, ".game", l) && // menu files
|
||||
!FS_IsExt(filename, ".cfg", l) && // for journal files
|
||||
!FS_IsDemoExt(filename, l)) // demos
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue