Skip to content

Commit f33217a

Browse files
committed
rust: verify Mach-O binaries use 2 level namespace bindings
See inline comment for rationale. Related to #114.
1 parent 924693c commit f33217a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/validation.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use {
1111
FileHeader32, FileHeader64, ET_DYN, ET_EXEC, STB_GLOBAL, STB_WEAK, STV_DEFAULT,
1212
STV_HIDDEN,
1313
},
14-
macho::{MachHeader32, MachHeader64},
14+
macho::{MachHeader32, MachHeader64, MH_OBJECT, MH_TWOLEVEL},
1515
read::{
1616
elf::{Dyn, FileHeader, SectionHeader, Sym},
1717
macho::{LoadCommandVariant, MachHeader, Nlist},
@@ -848,6 +848,13 @@ fn validate_macho<Mach: MachHeader<Endian = Endianness>>(
848848
));
849849
}
850850

851+
if header.filetype(endian) != MH_OBJECT && header.flags(endian) & MH_TWOLEVEL == 0 {
852+
context.errors.push(format!(
853+
"{} does not use two-level symbol lookup",
854+
path.display()
855+
));
856+
}
857+
851858
let mut load_commands = header.load_commands(endian, bytes, 0)?;
852859

853860
let mut dylib_names = vec![];
@@ -909,7 +916,7 @@ fn validate_macho<Mach: MachHeader<Endian = Endianness>>(
909916

910917
// Don't perform undefined symbol analysis for object files because the object file
911918
// in isolation lacks context.
912-
if header.filetype(endian) != object::macho::MH_OBJECT {
919+
if header.filetype(endian) != MH_OBJECT {
913920
for symbol in undefined_symbols {
914921
// Assume undefined symbols provided by current library will resolve.
915922
if symbol.library_ordinal == object::macho::SELF_LIBRARY_ORDINAL {

0 commit comments

Comments
 (0)