From 1b38ceb0d4bb4ae32cb93c295e3ef493b91f9a78 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Thu, 28 May 2015 13:49:23 +0200 Subject: + Fixed defects found by Coverity (well, most of them) --- src/SFileCompactArchive.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/SFileCompactArchive.cpp') diff --git a/src/SFileCompactArchive.cpp b/src/SFileCompactArchive.cpp index be1ca66..5b6cbe3 100644 --- a/src/SFileCompactArchive.cpp +++ b/src/SFileCompactArchive.cpp @@ -530,8 +530,7 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const char * szListFile, bool /* bR ULONGLONG ByteOffset; ULONGLONG ByteCount; LPDWORD pFileKeys = NULL; - TCHAR szTempFile[MAX_PATH] = _T(""); - TCHAR * szTemp = NULL; + TCHAR szTempFile[MAX_PATH+1] = _T(""); int nError = ERROR_SUCCESS; // Test the valid parameters @@ -568,12 +567,11 @@ bool WINAPI SFileCompactArchive(HANDLE hMpq, const char * szListFile, bool /* bR // Get the temporary file name and create it if(nError == ERROR_SUCCESS) { - _tcscpy(szTempFile, FileStream_GetFileName(ha->pStream)); - if((szTemp = _tcsrchr(szTempFile, '.')) != NULL) - _tcscpy(szTemp + 1, _T("mp_")); - else - _tcscat(szTempFile, _T("_")); + // Create temporary file name. Prevent buffer overflow + StringCopyT(szTempFile, FileStream_GetFileName(ha->pStream), MAX_PATH); + StringCatT(szTempFile, _T(".tmp"), MAX_PATH); + // Create temporary file pTempStream = FileStream_CreateFile(szTempFile, STREAM_PROVIDER_FLAT | BASE_PROVIDER_FILE); if(pTempStream == NULL) nError = GetLastError(); -- cgit v1.2.3