Skip to content

Commit

Permalink
Add a bounds check to protect against an empty vector from GetArgs(),…
Browse files Browse the repository at this point in the history
… which

can cause an out of bounds access in GetCurrentExecutableName(). One way this
can happen is if the user forgets to call InitGoogleTest().

PiperOrigin-RevId: 647740658
Change-Id: Id87692aa3d515b8ae0836e474be477d2aafa3871
  • Loading branch information
Abseil Team authored and copybara-github committed Jun 28, 2024
1 parent 1d17ea1 commit 34ad51b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,14 @@ ::std::vector<std::string> GetArgvs() {
FilePath GetCurrentExecutableName() {
FilePath result;

auto args = GetArgvs();
if (!args.empty()) {
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2)
result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe"));
result.Set(FilePath(args[0]).RemoveExtension("exe"));
#else
result.Set(FilePath(GetArgvs()[0]));
result.Set(FilePath(args[0]));
#endif // GTEST_OS_WINDOWS
}

return result.RemoveDirectoryName();
}
Expand Down

0 comments on commit 34ad51b

Please sign in to comment.