summaryrefslogtreecommitdiff
path: root/src/qcommon/files.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qcommon/files.c')
-rw-r--r--src/qcommon/files.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/qcommon/files.c b/src/qcommon/files.c
index 0228a4be..53385244 100644
--- a/src/qcommon/files.c
+++ b/src/qcommon/files.c
@@ -382,7 +382,7 @@ static fileHandle_t FS_HandleForFile(void) {
static FILE *FS_FileForHandle( fileHandle_t f ) {
if ( f < 0 || f > MAX_FILE_HANDLES ) {
- Com_Error( ERR_DROP, "FS_FileForHandle: out of reange" );
+ Com_Error( ERR_DROP, "FS_FileForHandle: out of range" );
}
if (fsh[f].zipFile == qtrue) {
Com_Error( ERR_DROP, "FS_FileForHandle: can't get FILE on zip file" );
@@ -497,6 +497,24 @@ static qboolean FS_CreatePath (char *OSPath) {
/*
=================
+FS_FilenameIsExecutable
+
+ERR_FATAL if trying to maniuplate a file with the platform library extension
+=================
+ */
+static void FS_FilenameIsExecutable( const char *filename, const char *function )
+{
+ // Check if the filename ends with the library extension
+ if( !Q_stricmp( filename + strlen( filename ) - strlen( DLL_EXT ), DLL_EXT ) )
+ {
+ Com_Error( ERR_FATAL, "%s: Not allowed to write '%s' due to %s extension\n",
+ function, filename, DLL_EXT );
+ }
+}
+
+
+/*
+=================
FS_CopyFile
Copy a fully specified file from one place to another
@@ -509,6 +527,8 @@ static void FS_CopyFile( char *fromOSPath, char *toOSPath ) {
Com_Printf( "copy %s to %s\n", fromOSPath, toOSPath );
+ FS_FilenameIsExecutable( toOSPath, __FUNCTION__ );
+
if (strstr(fromOSPath, "journal.dat") || strstr(fromOSPath, "journaldata.dat")) {
Com_Printf( "Ignoring journal files\n");
return;
@@ -550,6 +570,8 @@ FS_Remove
===========
*/
void FS_Remove( const char *osPath ) {
+ FS_FilenameIsExecutable( osPath, __FUNCTION__ );
+
remove( osPath );
}
@@ -560,6 +582,8 @@ FS_HomeRemove
===========
*/
void FS_HomeRemove( const char *homePath ) {
+ FS_FilenameIsExecutable( homePath, __FUNCTION__ );
+
remove( FS_BuildOSPath( fs_homepath->string,
fs_gamedir, homePath ) );
}
@@ -637,6 +661,8 @@ fileHandle_t FS_SV_FOpenFileWrite( const char *filename ) {
Com_Printf( "FS_SV_FOpenFileWrite: %s\n", ospath );
}
+ FS_FilenameIsExecutable( ospath, __FUNCTION__ );
+
if( FS_CreatePath( ospath ) ) {
return 0;
}
@@ -716,7 +742,8 @@ int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ) {
if (f) {
return FS_filelength(f);
}
- return 0;
+
+ return -1;
}
@@ -745,6 +772,8 @@ void FS_SV_Rename( const char *from, const char *to ) {
Com_Printf( "FS_SV_Rename: %s --> %s\n", from_ospath, to_ospath );
}
+ FS_FilenameIsExecutable( to_ospath, __FUNCTION__ );
+
if (rename( from_ospath, to_ospath )) {
// Failed, try copying it and deleting the original
FS_CopyFile ( from_ospath, to_ospath );
@@ -777,6 +806,8 @@ void FS_Rename( const char *from, const char *to ) {
Com_Printf( "FS_Rename: %s --> %s\n", from_ospath, to_ospath );
}
+ FS_FilenameIsExecutable( to_ospath, __FUNCTION__ );
+
if (rename( from_ospath, to_ospath )) {
// Failed, try copying it and deleting the original
FS_CopyFile ( from_ospath, to_ospath );
@@ -838,6 +869,8 @@ fileHandle_t FS_FOpenFileWrite( const char *filename ) {
Com_Printf( "FS_FOpenFileWrite: %s\n", ospath );
}
+ FS_FilenameIsExecutable( ospath, __FUNCTION__ );
+
if( FS_CreatePath( ospath ) ) {
return 0;
}
@@ -884,6 +917,8 @@ fileHandle_t FS_FOpenFileAppend( const char *filename ) {
Com_Printf( "FS_FOpenFileAppend: %s\n", ospath );
}
+ FS_FilenameIsExecutable( ospath, __FUNCTION__ );
+
if( FS_CreatePath( ospath ) ) {
return 0;
}
@@ -1086,8 +1121,10 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
temp = zfi->file;
// set the file position in the zip file (also sets the current file info)
unzSetCurrentFileInfoPosition(pak->handle, pakFile->pos);
- // copy the file info into the unzip structure
- Com_Memcpy( zfi, pak->handle, sizeof(unz_s) );
+ if ( zfi != pak->handle ) {
+ // copy the file info into the unzip structure
+ Com_Memcpy( zfi, pak->handle, sizeof(unz_s) );
+ }
// we copy this back into the structure
zfi->file = temp;
// open the file in the zip
@@ -2467,7 +2504,7 @@ qboolean FS_idPak( char *pak, char *base ) {
/*
================
-FS_idPak
+FS_CheckDirTraversal
Check whether the string contains stuff like "../" to prevent directory traversal bugs
and return qtrue if it does.
@@ -2777,6 +2814,7 @@ static void FS_Startup( const char *gameName )
Com_Printf( "%d files in pk3 files\n", fs_packFiles );
}
+
/*
=====================
FS_GamePureChecksum
@@ -2981,10 +3019,10 @@ const char *FS_ReferencedPakNames( void ) {
for ( search = fs_searchpaths ; search ; search = search->next ) {
// is the element a pak file?
if ( search->pack ) {
- if (*info) {
- Q_strcat(info, sizeof( info ), " " );
- }
if (search->pack->referenced || Q_stricmpn(search->pack->pakGamename, BASEGAME, strlen(BASEGAME))) {
+ if (*info) {
+ Q_strcat(info, sizeof( info ), " " );
+ }
Q_strcat( info, sizeof( info ), search->pack->pakGamename );
Q_strcat( info, sizeof( info ), "/" );
Q_strcat( info, sizeof( info ), search->pack->pakBasename );
@@ -3258,7 +3296,7 @@ int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode ) {
}
break;
default:
- Com_Error( ERR_FATAL, "FSH_FOpenFile: bad mode" );
+ Com_Error( ERR_FATAL, "FS_FOpenFileByMode: bad mode" );
return -1;
}