This is an archive of the discontinued LLVM Phabricator instance.

add fix-its for format-security warnings
ClosedPublic

Authored by bob.wilson on Mar 7 2016, 2:23 PM.

Details

Summary

The format-security warning is a special case of format-nonliteral that applies when there are no arguments besides the format string. In those cases, for printf and NSLog-style functions, there is an easy fix to provide a literal format string of "%s" (or @"%@" for Objective-C), with the nonliteral string as the argument. This patch teaches clang to provide fix-its for those cases.

Diff Detail

Event Timeline

bob.wilson updated this revision to Diff 49995.Mar 7 2016, 2:23 PM
bob.wilson retitled this revision from to add fix-its for format-security warnings.
bob.wilson updated this object.
bob.wilson added reviewers: bcraig, rjmccall, dblaikie.
bob.wilson added a subscriber: cfe-commits.
aprantl added a subscriber: aprantl.Mar 7 2016, 4:09 PM
bcraig edited edge metadata.Mar 8 2016, 6:07 AM

What about wprintf? Do we currently warn for wprintf(str)? If so, then the fixit probably needs to involve L"%ls".

mcrosier removed a subscriber: mcrosier.Mar 8 2016, 6:51 AM

What about wprintf? Do we currently warn for wprintf(str)? If so, then the fixit probably needs to involve L"%ls".

Darwin does not mark wprintf functions with an attribute. Linux (at least the version I checked) has an attribute that is commented out, but it uses a distinct "wprintf" format type. Clang does not currently support that format type. If that is added in the future, you are right that the fix-it will need to be different.

bcraig added a comment.Mar 8 2016, 9:13 AM

LGTM. I don't have a lot of authority over this code, so you may want to get a separate LGTM from someone else.

bob.wilson accepted this revision.Mar 11 2016, 2:00 PM
bob.wilson added a reviewer: bob.wilson.

Thanks Ben. Committed in r263299

This revision is now accepted and ready to land.Mar 11 2016, 2:00 PM
bob.wilson closed this revision.Mar 11 2016, 2:01 PM