mirror of
https://github.com/google/googletest.git
synced 2024-12-26 01:30:49 +08:00
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
This commit is contained in:
parent
1d17ea141d
commit
34ad51b3dc
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user