Skip to content

Audit code to ensure printf style templates are compile time constants. #15

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 4 commits into from
Sep 13, 2018

Conversation

rsgowman
Copy link
Member

When the format string is not, it could be imfluenced by error messages
or user input, and could possibly include illegal format specifiers
(such as %p). While not as dangerous as in C/C++, this can cause
exceptions to be thrown, which is especially bad, since the reason we're
printf'ing is typically because we're in the middle of error handling.

As part of this, I've audited usages of:

  • f.f.util.Assert.hardAssert
  • f.f.util.Assert.fail
  • f.f.util.Logger.warn
  • f.f.util.Logger.debug
  • java.lang.String.format

When the format string is not, it could be imfluenced by error messages
or user input, and could possibly include illegal format specifiers
(such as %p). While not as dangerous as in C/C++, this can cause
exceptions to be thrown, which is especially bad, since the reason we're
printf'ing is typically because we're in the middle of error handling.

As part of this, I've audited usages of:
- f.f.util.Assert.hardAssert
- f.f.util.Assert.fail
- f.f.util.Logger.warn
- f.f.util.Logger.debug
- java.lang.String.format
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -306,7 +306,7 @@ public void transactionsRequireCorrectDocumentReferences() {
try {
transaction.get(badRef);
} catch (FirebaseFirestoreException e) {
fail("transaction.get() triggered wrong exception: " + e);
fail("transaction.get() triggered wrong exception: %s", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this also be fail(e, "transaction.get ...")?

Copy link
Member Author

@rsgowman rsgowman Sep 12, 2018

Choose a reason for hiding this comment

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

Oops; there's two mistakes here:

Shouldn't this also be fail(e, "transaction.get ...")?

Mistake 1: yeah. Or it would be except:

2: This is actually junit's fail() method, not Assert.fail(), and thus, this line should've been unchanged. Fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there's a few more of these too. I'll recheck *Test.java.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@rsgowman rsgowman merged commit a0f26e0 into master Sep 13, 2018
@rsgowman rsgowman deleted the rsgowman/printf branch September 13, 2018 01:21
@firebase firebase locked and limited conversation to collaborators Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants