Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only parse /bin/sh (not /bin/ls) #1493

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions crates/platform-host/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,17 @@ fn get_musl_version(ld_path: impl AsRef<Path>) -> std::io::Result<Option<(u16, u

/// Find musl libc path from executable's ELF header.
fn find_libc() -> Result<PathBuf, PlatformError> {
// We'll try to parse the first file we read successfully
for path in ["/bin/ls", "/bin/sh"] {
let Ok(buffer) = fs::read(path) else {
continue;
};
let elf = Elf::parse(&buffer).map_err(|err| {
PlatformError::OsVersionDetectionError(format!(
"Couldn't parse {path} to detect the ld version: {err}"
))
})?;
if let Some(elf_interpreter) = elf.interpreter {
return Ok(PathBuf::from(elf_interpreter));
}

return Err(PlatformError::OsVersionDetectionError(format!(
"Couldn't parse {path} to detect the ld version"
)));
let buffer = fs::read("/bin/sh")?;
let error_str = "Couldn't parse /bin/sh for detecting the ld version";
let elf = Elf::parse(&buffer)
.map_err(|err| PlatformError::OsVersionDetectionError(format!("{error_str}: {err}")))?;
if let Some(elf_interpreter) = elf.interpreter {
Ok(PathBuf::from(elf_interpreter))
} else {
Err(PlatformError::OsVersionDetectionError(
error_str.to_string(),
))
}
Err(PlatformError::OsVersionDetectionError(
"Failed to find binary at `/bin/ls` or `/bin/sh` to read ld version from".to_string(),
))
}

#[cfg(test)]
Expand Down