From 936db459eef752340bcb2416d9c8cb809e9bd0b2 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 24 Apr 2013 14:11:18 -0500 Subject: [PATCH] Don't allow modifying qvms or pk3s Exception for allowing pk3s to be downloaded. --- code/client/cl_curl.c | 2 +- code/client/cl_parse.c | 2 +- code/qcommon/files.c | 16 ++++++++++------ code/qcommon/qcommon.h | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/code/client/cl_curl.c b/code/client/cl_curl.c index 3debd6ed..901ef999 100644 --- a/code/client/cl_curl.c +++ b/code/client/cl_curl.c @@ -304,7 +304,7 @@ void CL_cURL_PerformDownload(void) } FS_FCloseFile(clc.download); if(msg->msg == CURLMSG_DONE && msg->data.result == CURLE_OK) { - FS_SV_Rename(clc.downloadTempName, clc.downloadName); + FS_SV_Rename(clc.downloadTempName, clc.downloadName, qfalse); clc.downloadRestart = qtrue; } else { diff --git a/code/client/cl_parse.c b/code/client/cl_parse.c index d540284c..3db34bcc 100644 --- a/code/client/cl_parse.c +++ b/code/client/cl_parse.c @@ -637,7 +637,7 @@ void CL_ParseDownload ( msg_t *msg ) { clc.download = 0; // rename the file - FS_SV_Rename ( clc.downloadTempName, clc.downloadName ); + FS_SV_Rename ( clc.downloadTempName, clc.downloadName, qfalse ); } // send intentions now diff --git a/code/qcommon/files.c b/code/qcommon/files.c index de15a2ea..a9234695 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -554,17 +554,19 @@ qboolean FS_CreatePath (char *OSPath) { ================= FS_CheckFilenameIsNotExecutable -ERR_FATAL if trying to maniuplate a file with the platform library extension +ERR_FATAL if trying to maniuplate a file with the platform library, QVM, or pk3 extension ================= */ static void FS_CheckFilenameIsNotExecutable( const char *filename, const char *function ) { - // Check if the filename ends with the library extension - if(COM_CompareExtension(filename, DLL_EXT)) + // Check if the filename ends with the library, QVM, or pk3 extension + if( COM_CompareExtension( filename, DLL_EXT ) + || COM_CompareExtension( filename, ".qvm" ) + || COM_CompareExtension( filename, ".pk3" ) ) { Com_Error( ERR_FATAL, "%s: Not allowed to manipulate '%s' due " - "to %s extension", function, filename, DLL_EXT ); + "to %s extension", function, filename, COM_GetExtension( filename ) ); } } @@ -765,7 +767,7 @@ FS_SV_Rename =========== */ -void FS_SV_Rename( const char *from, const char *to ) { +void FS_SV_Rename( const char *from, const char *to, qboolean safe ) { char *from_ospath, *to_ospath; if ( !fs_searchpaths ) { @@ -784,7 +786,9 @@ void FS_SV_Rename( const char *from, const char *to ) { Com_Printf( "FS_SV_Rename: %s --> %s\n", from_ospath, to_ospath ); } - FS_CheckFilenameIsNotExecutable( to_ospath, __func__ ); + if ( safe ) { + FS_CheckFilenameIsNotExecutable( to_ospath, __func__ ); + } rename(from_ospath, to_ospath); } diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 51c443fb..349953db 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -641,7 +641,7 @@ fileHandle_t FS_FCreateOpenPipeFile( const char *filename ); fileHandle_t FS_SV_FOpenFileWrite( const char *filename ); long FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ); -void FS_SV_Rename( const char *from, const char *to ); +void FS_SV_Rename( const char *from, const char *to, qboolean safe ); long FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE ); // if uniqueFILE is true, then a new FILE will be fopened even if the file // is found in an already open pak file. If uniqueFILE is false, you must call