mirror of
https://github.com/yhirose/cpp-httplib
synced 2026-06-08 18:30:49 +00:00
Fix #2425
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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([&] {
|
||||
|
||||
Reference in New Issue
Block a user