From 83f1084601c87f958127cb78789fbd421d0555f4 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Wed, 27 Nov 2024 02:07:13 +0000 Subject: [PATCH] boulder: Also handle DT_RUNPATH in conjunction with DT_RPATH... Signed-off-by: Ikey Doherty --- boulder/src/package/analysis/handler/elf.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/boulder/src/package/analysis/handler/elf.rs b/boulder/src/package/analysis/handler/elf.rs index ad1064a1..7d9f9355 100644 --- a/boulder/src/package/analysis/handler/elf.rs +++ b/boulder/src/package/analysis/handler/elf.rs @@ -5,7 +5,7 @@ use std::{ }; use elf::{ - abi::{DT_NEEDED, DT_RPATH, DT_SONAME}, + abi::{DT_NEEDED, DT_RPATH, DT_RUNPATH, DT_SONAME}, endian::AnyEndian, file::Class, note::Note, @@ -100,6 +100,7 @@ fn parse_dynamic_section( let mut needed_offsets = vec![]; let mut soname_offset = None; let mut rpath_offset = vec![]; + let mut runpath_offset = vec![]; // i.e `/` `usr` `lib` `libfoo.so.1.2.3` let in_root_tree = info.target_path.ancestors().skip(1).count() == 3; @@ -117,6 +118,9 @@ fn parse_dynamic_section( DT_RPATH => { rpath_offset.push(entry.d_val() as usize); } + DT_RUNPATH => { + runpath_offset.push(entry.d_val() as usize); + } _ => {} } } @@ -145,13 +149,14 @@ fn parse_dynamic_section( .and_then(|p| p.to_str()) .unwrap_or("/mason/install"); - // rpath list - for offset in rpath_offset { - if let Ok(val) = strtab.get(offset) { - for path in val.split(':') { - let path = path.replace("$ORIGIN", &origin); - rpaths.push(path); - } + for rpath in runpath_offset + .iter() + .chain(rpath_offset.iter()) + .filter_map(|v| strtab.get(*v).ok()) + { + for path in rpath.split(':') { + let path = path.replace("$ORIGIN", &origin); + rpaths.push(path); } }