posix: Always resolve symlinks to absolute paths

This avoids issues with mismatched paths when mixing Chromium and
OS filesystem functions. See https://crbug.com/40229712.
This commit is contained in:
Marshall Greenblatt 2024-06-17 17:52:26 -04:00
parent c44aa35bfc
commit 3b98dbda79
1 changed files with 21 additions and 6 deletions

View File

@ -103,13 +103,28 @@ base::FilePath NormalizePath(const cef_string_t& path_str,
path = path.StripTrailingSeparators();
}
if (!path.empty() && !path.IsAbsolute()) {
LOG(ERROR) << "The " << name << " directory (" << path.value()
<< ") is not an absolute path. Defaulting to empty.";
if (has_error) {
*has_error = true;
if (!path.empty()) {
if (!path.IsAbsolute()) {
LOG(ERROR) << "The " << name << " directory (" << path.value()
<< ") is not an absolute path. Defaulting to empty.";
if (has_error) {
*has_error = true;
}
return base::FilePath();
}
path = base::FilePath();
#if BUILDFLAG(IS_POSIX)
// Always resolve symlinks to absolute paths. This avoids issues with
// mismatched paths when mixing Chromium and OS filesystem functions.
// See https://crbug.com/40229712.
base::ScopedAllowBlockingForTesting allow_blocking;
const base::FilePath& resolved_path = base::MakeAbsoluteFilePath(path);
if (!resolved_path.empty()) {
return resolved_path;
} else if (errno != 0 && errno != ENOENT) {
PLOG(ERROR) << "realpath(" << path.value() << ") failed";
}
#endif // BUILDFLAG(IS_POSIX)
}
return path;