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

Fix bug with resolving relative symlinks during linux header detection #2038

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
16 changes: 15 additions & 1 deletion src/stirling/utils/linux_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,21 @@ StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::file
return error::Internal(ec.message());
}

const auto resolved_host_path = system::Config::GetInstance().ToHostPath(resolved);
// Relative paths containing "../" can result in an invalid host mount path when using
// ToHostPath. Therefore, we need to treat the absolute and relative cases differently.
std::filesystem::path resolved_host_path;
if (resolved.is_absolute()) {
resolved_host_path = system::Config::GetInstance().ToHostPath(resolved);
VLOG(1) << absl::Substitute(
"Symlink target is an absolute path. Converting that to host path: $0 -> $1.",
resolved.string(), resolved_host_path.string());
} else {
resolved_host_path = p.parent_path();
resolved_host_path /= resolved.string();
VLOG(1) << absl::Substitute(
"Symlink target is a relative path. Concatenating it to parent directory: $0",
resolved_host_path.string());
}

// Downstream won't be ok unless the resolved host path exists; return an error if needed.
if (!fs::Exists(resolved_host_path)) {
Expand Down
Loading