public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
[not found] <bug-39044-4@http.gcc.gnu.org/bugzilla/>
@ 2011-03-18 6:36 ` p4bgtech at gmail dot com
2012-05-06 4:51 ` bugdal at aerifal dot cx
2012-05-06 12:28 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: p4bgtech at gmail dot com @ 2011-03-18 6:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
p4bgtech at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |p4bgtech at gmail dot com
--- Comment #4 from p4bgtech at gmail dot com 2011-03-18 06:35:11 UTC ---
No warning displayed on gcc-4.5.1..
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
[not found] <bug-39044-4@http.gcc.gnu.org/bugzilla/>
2011-03-18 6:36 ` [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument p4bgtech at gmail dot com
@ 2012-05-06 4:51 ` bugdal at aerifal dot cx
2012-05-06 12:28 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2012-05-06 4:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
Rich Felker <bugdal at aerifal dot cx> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugdal at aerifal dot cx
--- Comment #5 from Rich Felker <bugdal at aerifal dot cx> 2012-05-06 04:23:14 UTC ---
This warning is valid and highly desirable. Any call to printf with a single
non-string-literal argument is almost surely an extremely serious security bug.
And there's rarely a legitimate reason to make such a call; the closest thing
to a legitimate use I can think of would be lazy/sloppy use of gettext. If the
string is not a format string, you should use fputs or fwrite to print it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
[not found] <bug-39044-4@http.gcc.gnu.org/bugzilla/>
2011-03-18 6:36 ` [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument p4bgtech at gmail dot com
2012-05-06 4:51 ` bugdal at aerifal dot cx
@ 2012-05-06 12:28 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-06 12:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |manu at gcc dot gnu.org
Resolution| |WONTFIX
--- Comment #6 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-06 12:26:36 UTC ---
(In reply to comment #2)
> Ah, you're right. Gentoo enables -Wformat-security by default now. I'll bug
> them about this.
>
> On the other hand, this does not generate a warning. Why?
printf(s) is always wrong. You should have used fputs().
To get a warning for printf(s,t), you need -Wformat=2 (or -Wformat-nonliteral).
I guess the reason is that there is no real alternative if you need such a
code.
(In reply to comment #3)
> i'd reconstruct this report as gcc not properly handling constant strings with
> printf() when the string is readily available to it and clearly does not change
In the examples here, the code is arguably safe, and GCC should not warn. But
to reach that conclusion, the front ends would need to do constant propagation,
and this is not implemented, and not likely to be ever implemented by existing
contributors. I think it would be widely useful to have some sort of constant
propagation in the FEs, but it would take someone extremely motivated and
skilled to get it done properly. Unfortunately, I am not aware of any
candidates. If you know of any, please let me know.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
2009-01-30 16:44 [Bug c/39044] New: " mano at roarinelk dot homelinux dot net
2009-01-31 1:10 ` [Bug c/39044] " pinskia at gcc dot gnu dot org
2009-01-31 6:14 ` mano at roarinelk dot homelinux dot net
@ 2009-02-25 23:58 ` vapier at gentoo dot org
2 siblings, 0 replies; 6+ messages in thread
From: vapier at gentoo dot org @ 2009-02-25 23:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from vapier at gentoo dot org 2009-02-25 23:58 -------
i'd reconstruct this report as gcc not properly handling constant strings with
printf() when the string is readily available to it and clearly does not change
as for the kernel and this warning flag, that's a different issue
--
vapier at gentoo dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |toolchain at gentoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
2009-01-30 16:44 [Bug c/39044] New: " mano at roarinelk dot homelinux dot net
2009-01-31 1:10 ` [Bug c/39044] " pinskia at gcc dot gnu dot org
@ 2009-01-31 6:14 ` mano at roarinelk dot homelinux dot net
2009-02-25 23:58 ` vapier at gentoo dot org
2 siblings, 0 replies; 6+ messages in thread
From: mano at roarinelk dot homelinux dot net @ 2009-01-31 6:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from mano at roarinelk dot homelinux dot net 2009-01-31 06:14 -------
(In reply to comment #1)
> GNU C (GCC) version 4.3.3 20081218 (prerelease) [gcc-4_3-branch revision
> 142804] (i386-apple-darwin8.11.1)
>
>
> Did you modify GCC at all?
Ah, you're right. Gentoo enables -Wformat-security by default now. I'll bug
them about this.
On the other hand, this does not generate a warning. Why?
---- 8< ------- 8< --------
#include <stdio.h>
int main()
{
static const char *s = "hello", *t = " world";
printf(s, t);
return 0;
}
----- 8< ------ 8< ---------
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument
2009-01-30 16:44 [Bug c/39044] New: " mano at roarinelk dot homelinux dot net
@ 2009-01-31 1:10 ` pinskia at gcc dot gnu dot org
2009-01-31 6:14 ` mano at roarinelk dot homelinux dot net
2009-02-25 23:58 ` vapier at gentoo dot org
2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-31 1:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-01-31 01:10 -------
[dhcp-10-98-10-23:~] apinski% ~/gcc4.3-gcc/bin/gcc -Wformat t.c -W -Wall
[dhcp-10-98-10-23:~] apinski% ~/gcc4.3-gcc/bin/gcc -Wformat t.c -W -Wall
-Wformat-security
t.c: In function 'main':
t.c:5: warning: format not a string literal and no format arguments
GNU C (GCC) version 4.3.3 20081218 (prerelease) [gcc-4_3-branch revision
142804] (i386-apple-darwin8.11.1)
Did you modify GCC at all?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39044
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-06 12:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-39044-4@http.gcc.gnu.org/bugzilla/>
2011-03-18 6:36 ` [Bug c/39044] -Wformat warns on printf() with stringpointer as sole argument p4bgtech at gmail dot com
2012-05-06 4:51 ` bugdal at aerifal dot cx
2012-05-06 12:28 ` manu at gcc dot gnu.org
2009-01-30 16:44 [Bug c/39044] New: " mano at roarinelk dot homelinux dot net
2009-01-31 1:10 ` [Bug c/39044] " pinskia at gcc dot gnu dot org
2009-01-31 6:14 ` mano at roarinelk dot homelinux dot net
2009-02-25 23:58 ` vapier at gentoo dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).