From 34ad51b3dc4f922d8ab622491dd44fc2c39afee9 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 28 Jun 2024 11:12:00 -0700 Subject: 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 --- googletest/src/gtest.cc | 7 +++++-- 1 file 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 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(); } -- cgit v0.12