Skip to content

Commit d7f067a

Browse files
yannhamclaude
andcommitted
fix: handle pathnames with spaces in /proc/self/maps parser
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 019a63c commit d7f067a

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

libdd-otel-thread-ctx/src/sanity_check.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
//! that the binary was linked with the correct option:
1010
//!
1111
//! - `otel_thread_ctx_v1` is exported as TLS GLOBAL in the dynamic symbol table.
12-
//! - `otel_thread_ctx_v1` follows the TLSDESC model: there's either no relocation in `.rela.dyn`
13-
//! (Local Exec), or a TLSDESC one. All other TLS relocation types (DTPMOD, DTPOFF, TPOFF,
14-
//! GOTTPOFF, etc.) are rejected.
12+
//! - `otel_thread_ctx_v1` has no non-TLSDESC TLS relocations in `.rela.dyn`. The linker may pick
13+
//! TLSDESC or Local Exec depending on optimization; both are acceptable. All other TLS relocation
14+
//! types (DTPMOD, DTPOFF, TPOFF, GOTTPOFF, etc.) are rejected.
1515
//!
1616
//! This module is only available on Linux (the only platform that supports the TLSDESC dialect used
1717
//! by this crate) and only when the `sanity-check` feature is enabled.
@@ -51,15 +51,26 @@ fn own_elf_path() -> anyhow::Result<PathBuf> {
5151
std::fs::read_to_string("/proc/self/maps").context("failed to read /proc/self/maps")?;
5252
for line in maps.lines() {
5353
// Format: address perms offset dev inode [pathname]
54-
let fields: Vec<&str> = line.split_whitespace().collect();
55-
if fields.len() < 6 {
56-
continue;
54+
// Skip the first 5 whitespace-delimited tokens then take the rest verbatim
55+
// as the path, so that pathnames containing spaces are preserved intact.
56+
let mut rest = line;
57+
58+
for _ in 0..5 {
59+
rest = rest.trim_start_matches(|c: char| c.is_ascii_whitespace());
60+
rest = rest.trim_start_matches(|c: char| !c.is_ascii_whitespace());
5761
}
58-
let path = fields[5];
62+
63+
let path = rest.trim_start_matches(|c: char| c.is_ascii_whitespace());
64+
5965
if !path.starts_with('/') {
6066
continue;
6167
}
62-
if let Some((start_str, end_str)) = fields[0].split_once('-') {
68+
69+
if let Some((start_str, end_str)) = line
70+
.split_whitespace()
71+
.next()
72+
.and_then(|f| f.split_once('-'))
73+
{
6374
let start = usize::from_str_radix(start_str, 16).unwrap_or(0);
6475
let end = usize::from_str_radix(end_str, 16).unwrap_or(0);
6576
if addr >= start && addr < end {

0 commit comments

Comments
 (0)