Skip to content

Commit

Permalink
rust: verify Mach-O binaries use 2 level namespace bindings
Browse files Browse the repository at this point in the history
See inline comment for rationale. Related to #114.
  • Loading branch information
indygreg committed May 1, 2022
1 parent 5f01d43 commit 94ef265
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
FileHeader32, FileHeader64, ET_DYN, ET_EXEC, STB_GLOBAL, STB_WEAK, STV_DEFAULT,
STV_HIDDEN,
},
macho::{MachHeader32, MachHeader64},
macho::{MachHeader32, MachHeader64, MH_OBJECT, MH_TWOLEVEL},
read::{
elf::{Dyn, FileHeader, SectionHeader, Sym},
macho::{LoadCommandVariant, MachHeader, Nlist},
Expand Down Expand Up @@ -848,6 +848,13 @@ fn validate_macho<Mach: MachHeader<Endian = Endianness>>(
));
}

if header.filetype(endian) != MH_OBJECT && header.flags(endian) & MH_TWOLEVEL == 0 {
context.errors.push(format!(
"{} does not use two-level symbol lookup",
path.display()
));
}

let mut load_commands = header.load_commands(endian, bytes, 0)?;

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

// Don't perform undefined symbol analysis for object files because the object file
// in isolation lacks context.
if header.filetype(endian) != object::macho::MH_OBJECT {
if header.filetype(endian) != MH_OBJECT {
for symbol in undefined_symbols {
// Assume undefined symbols provided by current library will resolve.
if symbol.library_ordinal == object::macho::SELF_LIBRARY_ORDINAL {
Expand Down

0 comments on commit 94ef265

Please sign in to comment.