Skip to content

Commit

Permalink
Fix crash when calling absPath with empty input
Browse files Browse the repository at this point in the history
Signed-off-by: Zhilei Ren <[email protected]>
  • Loading branch information
gzfuzz committed Aug 1, 2024
1 parent ad1d5ad commit 7c47da2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ std::string common::copyToUnixPath(const std::string &_path)
/////////////////////////////////////////////////
std::string common::absPath(const std::string &_path)
{
return fs::absolute(_path).string();
std::error_code ec;
auto path = fs::absolute(_path, ec);
if (!fsWarn("absPath", ec))
{
path = "";
}

return path.string();
}

/////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions src/Filesystem_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,9 @@ TEST_F(FilesystemTest, separator)
EXPECT_EQ("\\", gz::common::separator(""));
#endif
}

/////////////////////////////////////////////////
TEST_F(FilesystemTest, empty)
{
EXPECT_EQ(common::absPath(""), "");
}

0 comments on commit 7c47da2

Please sign in to comment.