mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-10 19:39:52 -05:00
Normalize PWD environment variable before using it
In commit 5aed3ee49d (cmSystemTools: Add GetLogicalWorkingDirectory,
2024-10-28, v4.0.0-rc1~528^2~6) we incorrectly trusted `PWD` to be a
normalized path so long as its realpath matches the current working
directory.
Fixes: #26870
This commit is contained in:
@@ -3007,10 +3007,11 @@ std::string InitLogicalWorkingDirectory()
|
||||
{
|
||||
std::string cwd = cmsys::SystemTools::GetCurrentWorkingDirectory();
|
||||
std::string pwd;
|
||||
if (cmSystemTools::GetEnv("PWD", pwd)) {
|
||||
if (cmSystemTools::GetEnv("PWD", pwd) &&
|
||||
cmSystemTools::FileIsFullPath(pwd)) {
|
||||
std::string const pwd_real = cmSystemTools::GetRealPath(pwd);
|
||||
if (pwd_real == cwd) {
|
||||
cwd = std::move(pwd);
|
||||
cwd = cmSystemTools::ToNormalizedPathOnDisk(std::move(pwd));
|
||||
}
|
||||
}
|
||||
return cwd;
|
||||
|
||||
Reference in New Issue
Block a user