Closed
Bug 521677
Opened 16 years ago
Closed 16 years ago
Fix build warnings: "format not a string literal and no format arguments"
Categories
(Core :: General, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: dholbert, Assigned: dholbert)
References
()
Details
(Whiteboard: [build_warning])
Attachments
(1 file, 2 obsolete files)
|
5.35 KB,
patch
|
dbaron
:
review+
|
Details | Diff | Splinter Review |
When building mozilla-central, I get 14 warnings of this type (in various files):
> mozilla/xpcom/base/nsTraceRefcntImpl.cpp:820: warning: format not a string literal and no format arguments
This is GCC detecting a potential format string attack ( http://en.wikipedia.org/wiki/Format_string_attack ). This is really only an issue when the printed string is user-controlled, but it's trivial to fix, so I don't see why we shouldn't just fix it.
Attached patch fixes 8 instances of this problem in mozilla-central. (The remaining 6 are in NSS.)
| Assignee | ||
Updated•16 years ago
|
Attachment #405791 -
Flags: review?(dbaron)
| Assignee | ||
Comment 1•16 years ago
|
||
I filed bug 521679 on the instances of this warning in NSS code.
In some cases these might better use fputs or puts. Or, in the case of ShowXPCException, combine the two printfs into one.
| Assignee | ||
Comment 3•16 years ago
|
||
This patch uses fputs instead of fprintf, for all fprintf calls touched by the previous patch.
I didn't switch all the printf calls to puts, though, because puts always adds a newline[1], and so the switch would change our behavior.
I did replace the |printf(str); printf("\n");| in ShowXPCException to use a single puts call, though.
[1]
http://www.opengroup.org/onlinepubs/009695399/functions/fputs.html#tag_03_182_07
http://www.qnx.com/developers/docs/6.4.1/dinkum_en/ecpp/stdio.html#puts
Attachment #405791 -
Attachment is obsolete: true
Attachment #407022 -
Flags: review?(dbaron)
Attachment #405791 -
Flags: review?(dbaron)
Actually, I'd forgotten that puts outputs a newline (whereas fputs doesn't). So what I'd actually suggest is switching to fputs in almost all cases (with an explicit 'stdout' argument), and continuing to use printf in the one case where you used puts.
| Assignee | ||
Comment 5•16 years ago
|
||
Ok -- this version replaces all printfs with fputs(str, stdout), except for the one case in in ShowXPCException, which is now "printf("%s\n", str);" as you suggested in comment 2.
Attachment #407022 -
Attachment is obsolete: true
Attachment #407027 -
Flags: review?(dbaron)
Attachment #407022 -
Flags: review?(dbaron)
Comment on attachment 407027 [details] [diff] [review]
fix v3: replace printf's with fputs(str, stdout)
r=dbaron. Thanks for redoing it.
Attachment #407027 -
Flags: review?(dbaron) → review+
| Assignee | ||
Comment 7•16 years ago
|
||
No prob, thanks for the review!
Pushed: http://hg.mozilla.org/mozilla-central/rev/872a2ad2af5d
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
| Assignee | ||
Updated•16 years ago
|
Assignee: nobody → dholbert
| Assignee | ||
Updated•16 years ago
|
Whiteboard: [build_warning]
You need to log in
before you can comment on or make changes to this bug.
Description
•