-
Notifications
You must be signed in to change notification settings - Fork 612
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
Conversation
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
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.
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); |
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.
Shouldn't this also be fail(e, "transaction.get ...")?
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.
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.
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.
I think there's a few more of these too. I'll recheck *Test.java.
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.
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: