This commit is contained in:
yhirose
2026-04-12 17:25:41 -04:00
parent ee5d15c842
commit 7e2a173072
2 changed files with 12 additions and 1 deletions
+6 -1
View File
@@ -4889,10 +4889,15 @@ inline bool canonicalize_path(const char *path, std::string &resolved) {
char buf[_MAX_PATH];
if (_fullpath(buf, path, _MAX_PATH) == nullptr) { return false; }
resolved = buf;
#else
#elif defined(PATH_MAX)
char buf[PATH_MAX];
if (realpath(path, buf) == nullptr) { return false; }
resolved = buf;
#else
auto buf = realpath(path, nullptr);
auto guard = scope_exit([&]() { std::free(buf); });
if (buf == nullptr) { return false; }
resolved = buf;
#endif
return true;
}
+6
View File
@@ -17540,8 +17540,14 @@ TEST(SymlinkTest, SymlinkEscapeFromBaseDirectory) {
}
// Create symlink using absolute path so it resolves correctly
#ifdef PATH_MAX
char abs_secret[PATH_MAX];
ASSERT_NE(nullptr, realpath(secret_dir.c_str(), abs_secret));
#else
auto abs_secret = realpath(secret_dir.c_str(), nullptr);
auto abs_secret_guard = detail::scope_exit([&]() { std::free(abs_secret); });
ASSERT_NE(nullptr, abs_secret);
#endif
ASSERT_EQ(0, symlink(abs_secret, symlink_path.c_str()));
auto se = detail::scope_exit([&] {