Update pefile.cpp

I found a bug by participating to the Binary Golf Grand Prix 3 (https://tmpout.sh/bggp/3/) : upx text.exe segfaults when NumberOfSections in the IMAGE_FILE_HEADER is NULL, so 
if (memcmp(isection[0].name,"UPX",3) == 0) triggers a NULL pointer dereference causing a crash.
To fix it, just have to check if isection is NULL (which means NumberOfSections = 0) or not.
This commit is contained in:
S01den 2022-07-27 01:54:01 +02:00 committed by Markus F.X.J. Oberhumer
parent acad3c3000
commit 077793fa5e
1 changed files with 4 additions and 1 deletions

View File

@ -2165,7 +2165,10 @@ void PeFile::checkHeaderValues(unsigned subsystem, unsigned mask,
//check CLR Runtime Header directory entry
if (IDSIZE(PEDIR_COMRT))
throwCantPack(".NET files are not yet supported");
if(isection == NULL)
throwCantPack("No section was found");
if (memcmp(isection[0].name,"UPX",3) == 0)
throwAlreadyPackedByUPX();