]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Add a bounds check to protect against an empty vector from GetArgs(), which
authorAbseil Team <absl-team@google.com>
Fri, 28 Jun 2024 18:12:00 +0000 (11:12 -0700)
committerCopybara-Service <copybara-worker@google.com>
Fri, 28 Jun 2024 18:12:56 +0000 (11:12 -0700)
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

googletest/src/gtest.cc

index 9a17180b3530310a7b53e813ca7552f244d22353..6662a13ce1455f737eb631f667f22aea36531f9c 100644 (file)
@@ -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();
 }