-
Notifications
You must be signed in to change notification settings - Fork 125
Ensure that argv specified to googletest has a null terminator. #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Integration test succeeded!Requested by @dconeybe on commit ba9d52e |
@@ -309,13 +309,17 @@ std::vector<std::string> ArgcArgvToVector(int argc, char* argv[]) { | |||
|
|||
char** VectorToArgcArgv(const std::vector<std::string>& args_vector, | |||
int* argc) { | |||
char** argv = new char*[args_vector.size()]; | |||
// Create `argv` one element larger than strictly required since gtest expects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this is a POSIX requirement -- if so, it should probably be mentioned in this comment (otherwise, it reads as if it's a requirement imposed by Googletest).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…googletest filters to modified_args
According to https://man7.org/linux/man-pages/man2/execve.2.html,
However, it appears that the
argv
specified tocommon_main()
is not terminated in this way, at least on Android. This causes googletest'sParseGoogleTestFlagsOnly()
function to read past the end ofargv
.https://github.com/google/googletest/blob/8d51ffdfab10b3fba636ae69bc03da4b54f8c235/googletest/src/gtest.cc#L6634-L6649
This doesn't usually lead to issues; however, when run with Address Sanitizer this causes a crash since it is technically referencing unallocated memory.
This PR works around this by explicitly adding a null terminator to
argv
.Googlers can see b/192351260#comment11 for more details.