From 6eddf12948230e24e462fd5a9b837940167f832b Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 26 Aug 2022 14:02:37 -0700 Subject: [PATCH] PDB parsing hardening --- IDEHelper/COFF.cpp | 19 +++++++++++-------- IDEHelper/WinDebugger.cpp | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/IDEHelper/COFF.cpp b/IDEHelper/COFF.cpp index 51f0fd99..33256b89 100644 --- a/IDEHelper/COFF.cpp +++ b/IDEHelper/COFF.cpp @@ -512,7 +512,6 @@ DbgType* COFF::CvGetType(int typeId) { TYPE_ENUM_e typeEnum = (TYPE_ENUM_e)typeId; DbgType* type = mCvSystemTypes[typeId]; - BF_ASSERT(type != NULL); return type; } @@ -3439,11 +3438,11 @@ CvCompileUnit* COFF::ParseCompileUnit(CvModuleInfo* moduleInfo, CvCompileUnit* c if (moduleInfo != NULL) { - BfLogDbgHI("ParseCompileUnit %s %s\n", mPDBPath.c_str(), moduleInfo->mModuleName); + BfLogDbg("ParseCompileUnit %s %s\n", mPDBPath.c_str(), moduleInfo->mModuleName); } else { - BfLogDbgHI("ParseCompileUnit %s NULL\n", mPDBPath.c_str()); + BfLogDbg("ParseCompileUnit %s NULL\n", mPDBPath.c_str()); } int allocSizeStart = mAlloc.GetAllocSize(); @@ -4127,6 +4126,8 @@ CvCompileUnit* COFF::ParseCompileUnit(int compileUnitId) int sectionSize = 0; uint8* sectionData = CvReadStream(moduleInfo->mStream, §ionSize); + if (sectionData == NULL) + return NULL; ParseCompileUnit(moduleInfo, NULL, sectionData, sectionSize); delete sectionData; return moduleInfo->mCompileUnit; @@ -4869,7 +4870,6 @@ uint8* COFF::CvReadStream(int streamIdx, int* outSize) if ((streamIdx < 0) || (streamIdx >= mCvStreamSizes.mSize)) { - Fail(StrFormat("Invalid PDB stream index: %d", streamIdx)); return NULL; } @@ -6257,10 +6257,13 @@ void COFF::ProcessDebugInfo() { compileUnit = ParseCompileUnit(NULL, compileUnit, entry.mData, entry.mSize); } - compileUnit->mLanguage = DbgLanguage_Beef; - mMasterCompileUnit->mLanguage = DbgLanguage_Beef; - MapCompileUnitMethods(compileUnit); - mEndTypeIdx = (int)linkedModule->mTypes.size(); + if (compileUnit != NULL) + { + compileUnit->mLanguage = DbgLanguage_Beef; + mMasterCompileUnit->mLanguage = DbgLanguage_Beef; + MapCompileUnitMethods(compileUnit); + mEndTypeIdx = (int)linkedModule->mTypes.size(); + } } } diff --git a/IDEHelper/WinDebugger.cpp b/IDEHelper/WinDebugger.cpp index f1fabb59..190c4457 100644 --- a/IDEHelper/WinDebugger.cpp +++ b/IDEHelper/WinDebugger.cpp @@ -9638,6 +9638,9 @@ static void PdbTestFile(WinDebugger* debugger, const StringImpl& path) for (int i = 0; i < coffFile.mTypes.mSize; i++) coffFile.mTypes[i]->PopulateType(); + + for (int i = 0; i < coffFile.mCvModuleInfo.mSize; i++) + coffFile.ParseCompileUnit(i); } static void PdbTest(WinDebugger* debugger, const StringImpl& path)