Merge pull request #9934 from nmeum/absPath-out-of-bounds

absPath: Explicitly check if path is empty before accessing it
This commit is contained in:
Eelco Dolstra 2024-02-05 14:44:02 +01:00 committed by GitHub
commit 6ec08b85f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,7 +25,7 @@ Path absPath(PathView path, std::optional<PathView> dir, bool resolveSymlinks)
{ {
std::string scratch; std::string scratch;
if (path[0] != '/') { if (path.empty() || path[0] != '/') {
// In this case we need to call `canonPath` on a newly-created // In this case we need to call `canonPath` on a newly-created
// string. We set `scratch` to that string first, and then set // string. We set `scratch` to that string first, and then set
// `path` to `scratch`. This ensures the newly-created string // `path` to `scratch`. This ensures the newly-created string