PE: Fix relocation parsing and validation

This commit is contained in:
Kornel Pal
2021-12-16 06:56:01 +01:00
committed by Markus F.X.J. Oberhumer
parent a09146b5e0
commit bfd1f1fbfa
+6 -3
View File
@@ -314,7 +314,7 @@ bool PeFile::Reloc::next(unsigned &pos,unsigned &type)
{ {
if (!rel) if (!rel)
newRelocPos(start); newRelocPos(start);
if (ptr_diff(rel, start) >= (int) size || rel->pagestart == 0) { if (ptr_diff(rel, start) >= (int) size) {
rel = nullptr; // rewind rel = nullptr; // rewind
return false; return false;
} }
@@ -375,7 +375,11 @@ void PeFile32::processRelocs() // pass1
unsigned const skip1 = IDADDR(PEDIR_RELOC); unsigned const skip1 = IDADDR(PEDIR_RELOC);
Reloc rel(ibuf.subref("bad reloc %#x", skip1, take1), take1); Reloc rel(ibuf.subref("bad reloc %#x", skip1, take1), take1);
const unsigned *counts = rel.getcounts(); const unsigned *counts = rel.getcounts();
const unsigned rnum = counts[1] + counts[2] + counts[3]; unsigned rnum = 0;
unsigned ic;
for (ic = 1; ic < 16; ic++)
rnum += counts[ic];
if (opt->win32_pe.strip_relocs || rnum == 0) if (opt->win32_pe.strip_relocs || rnum == 0)
{ {
@@ -390,7 +394,6 @@ void PeFile32::processRelocs() // pass1
return; return;
} }
unsigned ic;
for (ic = 15; ic > 3; ic--) for (ic = 15; ic > 3; ic--)
if (counts[ic]) if (counts[ic])
infoWarning("skipping unsupported relocation type %d (%d)",ic,counts[ic]); infoWarning("skipping unsupported relocation type %d (%d)",ic,counts[ic]);