diff options
author | unknown <E:\Ladik\Mail> | 2015-05-06 16:33:45 +0200 |
---|---|---|
committer | unknown <E:\Ladik\Mail> | 2015-05-06 16:33:45 +0200 |
commit | 3cfa7f2a1a81b226f5a5c3a43f4f9bd5704881f9 (patch) | |
tree | 8b99777e696e16f1cacc94b0b17b9b26a7b1d886 /src/SFileListFile.cpp | |
parent | abd17ec91e0ab54a9d29af02c36710c1ed4b0ee0 (diff) |
+ Fixed possible stack overflow in HashStringJenkins
+ StormLib now creates a listfile even for empty archives to make sure it will be maintained at later point when files are added to it
+ Bug fixes in listfile loading
Diffstat (limited to 'src/SFileListFile.cpp')
-rw-r--r-- | src/SFileListFile.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp index 90f71fa..f0d2122 100644 --- a/src/SFileListFile.cpp +++ b/src/SFileListFile.cpp @@ -77,22 +77,22 @@ static TListFileCache * CreateListFileCache(HANDLE hListFile, const char * szWil memset(pCache, 0, sizeof(TListFileCache) + cchWildCard); // Shall we copy the mask? - if(cchWildCard != NULL) + if(cchWildCard != 0) { pCache->szWildCard = (char *)(pCache + 1); memcpy(pCache->szWildCard, szWildCard, cchWildCard); } // Fill-in the rest of the cache pointers - pCache->pBegin = (LPBYTE)(pCache + 1) + cchWildCard + 1; + pCache->pBegin = (LPBYTE)(pCache + 1) + cchWildCard; // Load the entire listfile to the cache SFileReadFile(hListFile, pCache->pBegin, dwFileSize, &dwBytesRead, NULL); - if(dwFileSize != 0) + if(dwBytesRead != 0) { // Allocate pointers pCache->pPos = pCache->pBegin; - pCache->pEnd = pCache->pBegin + dwFileSize; + pCache->pEnd = pCache->pBegin + dwBytesRead; } else { @@ -302,6 +302,11 @@ static LPBYTE CreateListFile(TMPQArchive * ha, DWORD * pcbListFile) assert((size_t)(szListLine - szListFile) == cbListFile); } } + else + { + szListFile = STORM_ALLOC(char, 1); + cbListFile = 0; + } // Free the sort table STORM_FREE(SortTable); @@ -379,9 +384,6 @@ int SListFileSaveToMpq(TMPQArchive * ha) pbListFile = CreateListFile(ha, &cbListFile); if(pbListFile != NULL) { - // We expect it to be nonzero size - assert(cbListFile != 0); - // Determine the real flags for (listfile) if(ha->dwFileFlags1 == MPQ_FILE_EXISTS) ha->dwFileFlags1 = GetDefaultSpecialFileFlags(cbListFile, ha->pHeader->wFormatVersion); |