bool Parser<A>::LabelAndCFIBreakIterator::next(Parser<A>& parser, const Section<A>& sect, uint32_t sectNum, pint_t startAddr, pint_t endAddr,
pint_t* addr, pint_t* size, const macho_nlist<P>** symbol)
{
+ bool cfiApplicable = (sect.machoSection()->flags() & (S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS));
// may not be a label on start of section, but need atom demarcation there
if ( newSection ) {
newSection = false;
return true;
}
// no symbols in section, check CFI
- if ( cfiIndex < cfiStartsCount ) {
+ if ( cfiApplicable && (cfiIndex < cfiStartsCount) ) {
pint_t nextCfiAddr = cfiStartsArray[cfiIndex];
if ( nextCfiAddr < endAddr ) {
// use cfi
}
- // record range of sections
+ // validate just one segment
if ( segment == NULL )
throw "missing LC_SEGMENT";
+ if ( segment->filesize() > _fileLength )
+ throw "LC_SEGMENT filesize too large";
+
+ // record and validate sections
_sectionsStart = (macho_section<P>*)((char*)segment + sizeof(macho_segment_command<P>));
_machOSectionsCount = segment->nsects();
if ( (sizeof(macho_segment_command<P>) + _machOSectionsCount * sizeof(macho_section<P>)) > segment->cmdsize() )
throw "too many sections for size of LC_SEGMENT command";
+
return true;
}
Parser<x86_64>::TargetDesc target;
Parser<x86_64>::TargetDesc toTarget;
src.atom = this->findAtomByAddress(srcAddr);
+ if ( src.atom == NULL )
+ throwf("malformed mach-o, reloc addr 0x%llX not in any atom", srcAddr);
src.offsetInAtom = srcAddr - src.atom->_objAddress;
const uint8_t* fixUpPtr = file().fileContent() + sect->offset() + reloc->r_address();
uint64_t contentValue = 0;