Skip to content

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

Merged
merged 5 commits into from
Jul 21, 2021

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Jul 20, 2021

According to https://man7.org/linux/man-pages/man2/execve.2.html,

The argv array must be terminated by a NULL pointer. (Thus, in the new program, argv[argc] will be NULL.)

However, it appears that the argv specified to common_main() is not terminated in this way, at least on Android. This causes googletest's ParseGoogleTestFlagsOnly() function to read past the end of argv.

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.

@dconeybe dconeybe self-assigned this Jul 20, 2021
@google-cla google-cla bot added the cla: yes label Jul 20, 2021
@dconeybe dconeybe added the tests-requested: quick Trigger a quick set of integration tests. label Jul 20, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests-requested: quick Trigger a quick set of integration tests. labels Jul 20, 2021
@github-actions
Copy link

github-actions bot commented Jul 20, 2021

✅  Integration test succeeded!

Requested by @dconeybe on commit ba9d52e
Last updated: Wed Jul 21 18:25 PDT 2021
View integration test log & download artifacts

@jonsimantov jonsimantov self-requested a review July 20, 2021 19:03
@dconeybe dconeybe requested a review from var-const July 20, 2021 20:17
@dconeybe dconeybe removed their assignment Jul 20, 2021
@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jul 20, 2021
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 20, 2021
@jonsimantov jonsimantov added the no-lint Skip lint checks label Jul 20, 2021
@jonsimantov jonsimantov removed their request for review July 20, 2021 20:35
var-const
var-const previously approved these changes Jul 20, 2021
@@ -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
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@var-const var-const assigned dconeybe and unassigned var-const Jul 20, 2021
@dconeybe dconeybe enabled auto-merge (squash) July 21, 2021 13:45
@dconeybe dconeybe merged commit ba9d52e into main Jul 21, 2021
@github-actions github-actions bot added tests: in-progress This PR's integration tests are in progress. and removed tests: succeeded This PR's integration tests succeeded. labels Jul 21, 2021
@dconeybe dconeybe deleted the dconeybe/FixGoogleTestArgvEndingNull branch July 21, 2021 23:28
@github-actions github-actions bot added the tests: succeeded This PR's integration tests succeeded. label Jul 22, 2021
@firebase-workflow-trigger firebase-workflow-trigger bot removed the tests: in-progress This PR's integration tests are in progress. label Jul 22, 2021
@firebase firebase locked and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: firestore cla: yes no-lint Skip lint checks tests: succeeded This PR's integration tests succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants