include, lib: add __printf attributes to several function prototypes
Using __printf attributes helps to detect several format string issues at compile time (even though -Wformat-security is currently disabled in Makefile). For example it can detect when formatting a pointer as a number, like the issue fixed in commita3fa71c40f
("wl18xx: show rx_frames_per_rates as an array as it really is"), or when the arguments do not match the format string, c.f. for example commit5ce1aca814
("reiserfs: fix __RASSERT format string"). To prevent similar bugs in the future, add a __printf attribute to every function prototype which needs one in include/linux/ and lib/. These functions were mostly found by using gcc's -Wsuggest-attribute=format flag. Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Felipe Balbi <balbi@ti.com> Cc: Joel Becker <jlbec@evilplan.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
7f9be77555
commit
8db1486065
@@ -411,7 +411,8 @@ extern __printf(3, 0)
|
||||
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
|
||||
extern __printf(2, 3)
|
||||
char *kasprintf(gfp_t gfp, const char *fmt, ...);
|
||||
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
|
||||
extern __printf(2, 0)
|
||||
char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
|
||||
|
||||
extern __scanf(2, 3)
|
||||
int sscanf(const char *, const char *, ...);
|
||||
@@ -679,10 +680,10 @@ do { \
|
||||
__ftrace_vprintk(_THIS_IP_, fmt, vargs); \
|
||||
} while (0)
|
||||
|
||||
extern int
|
||||
extern __printf(2, 0) int
|
||||
__ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
|
||||
|
||||
extern int
|
||||
extern __printf(2, 0) int
|
||||
__ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
|
||||
|
||||
extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
|
||||
@@ -702,7 +703,7 @@ int trace_printk(const char *fmt, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline int
|
||||
static __printf(1, 0) inline int
|
||||
ftrace_vprintk(const char *fmt, va_list ap)
|
||||
{
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user