Skip to content

Commit

Permalink
Prevent crash with /proc path canonicalization
Browse files Browse the repository at this point in the history
The filesystem::canonical does not work very well with /proc paths,
explictly ignoring those paths from filesystem::canonical for now.
  • Loading branch information
xdrop committed Nov 19, 2020
1 parent 80d2d3c commit 41184dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,17 @@ uint32_t kernel_version(int attempt)

std::string abs_path(const std::string &rel_path)
{
auto p = std_filesystem::path(rel_path);
return std_filesystem::canonical(std_filesystem::absolute(p)).string();
// filesystem::canonical does not work very well with /proc paths
// failing during canonicalization. See iovisor:bpftrace#1595
if (rel_path.rfind("/proc", 0) != 0)
{
auto p = std_filesystem::path(rel_path);
return std_filesystem::canonical(std_filesystem::absolute(p)).string();
}
else
{
return rel_path;
}
}

} // namespace bpftrace
6 changes: 6 additions & 0 deletions tests/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ TEST(utils, parse_exponent)
EXPECT_EQ(parse_exponent((const char*)"2a9"), 2ULL);
}

TEST(utils, abs_path)
{
EXPECT_NO_THROW(
abs_path(std::string("/proc/1/root/usr/local/bin/usdt_test.so")));
}

} // namespace utils
} // namespace test
} // namespace bpftrace

0 comments on commit 41184dd

Please sign in to comment.