summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2024-06-28 18:12:00 (GMT)
committerCopybara-Service <copybara-worker@google.com>2024-06-28 18:12:56 (GMT)
commit34ad51b3dc4f922d8ab622491dd44fc2c39afee9 (patch)
tree911c199008c15cc73ac97228183c70f7b1a0f3e4
parent1d17ea141d2c11b8917d2c7d029f1c4e2b9769b2 (diff)
downloadgoogletest-34ad51b3dc4f922d8ab622491dd44fc2c39afee9.zip
googletest-34ad51b3dc4f922d8ab622491dd44fc2c39afee9.tar.gz
googletest-34ad51b3dc4f922d8ab622491dd44fc2c39afee9.tar.bz2
Add a bounds check to protect against an empty vector from GetArgs(), 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
-rw-r--r--googletest/src/gtest.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 9a17180..6662a13 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -661,11 +661,14 @@ static ::std::vector<std::string> g_argvs;
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();
}