From a70a9800220851555272cab6a61e2bb00b867ffb Mon Sep 17 00:00:00 2001 From: Ladislav Date: Sun, 12 Jan 2014 13:04:30 +0100 Subject: + Fixed crash when ha == NULL in SFileCreateFile --- src/SFileAddFile.cpp | 19 +++++++++++-------- test/Test.cpp | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/SFileAddFile.cpp b/src/SFileAddFile.cpp index fdc1524..1fa5873 100644 --- a/src/SFileAddFile.cpp +++ b/src/SFileAddFile.cpp @@ -685,16 +685,19 @@ bool WINAPI SFileCreateFile( nError = ERROR_INVALID_PARAMETER; // Don't allow to add file if the MPQ is open for read only - if(ha->dwFlags & MPQ_FLAG_READ_ONLY) - nError = ERROR_ACCESS_DENIED; + if(nError == ERROR_SUCCESS) + { + if(ha->dwFlags & MPQ_FLAG_READ_ONLY) + nError = ERROR_ACCESS_DENIED; - // Don't allow to add a file under pseudo-file name - if(IsPseudoFileName(szArchivedName, NULL)) - nError = ERROR_INVALID_PARAMETER; + // Don't allow to add a file under pseudo-file name + if(IsPseudoFileName(szArchivedName, NULL)) + nError = ERROR_INVALID_PARAMETER; - // Don't allow to add any of the internal files - if(IsInternalMpqFileName(szArchivedName)) - nError = ERROR_INTERNAL_FILE; + // Don't allow to add any of the internal files + if(IsInternalMpqFileName(szArchivedName)) + nError = ERROR_INTERNAL_FILE; + } // Perform validity check of the MPQ flags if(nError == ERROR_SUCCESS) diff --git a/test/Test.cpp b/test/Test.cpp index f3d4d5a..25f63fb 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -3428,6 +3428,9 @@ int main(int argc, char * argv[]) // if(nError == ERROR_SUCCESS) // nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\06080", "2004 - WoW\\06299"); + HANDLE hFile = NULL; + SFileCreateFile(NULL, "huhu", 0, 260, 0, MPQ_FILE_COMPRESS, &hFile); + // Search all testing archives and verify their SHA1 hash if(nError == ERROR_SUCCESS) nError = FindFiles(ForEachFile_VerifyFileChecksum, szMpqSubDir); -- cgit v1.2.3