Browse code

Use av_printf_format to check the usage of printf style functions

This helps catching cases where the format string doesn't
match what is passed in, or injection bugs where user data
is passed in as format string.

Signed-off-by: Martin Storsjö <martin@martin.st>

Martin Storsjö authored on 2011/06/17 16:31:11
Showing 6 changed files
... ...
@@ -4143,7 +4143,7 @@ void av_log_missing_feature(void *avc, const char *feature, int want_sample);
4143 4143
  * a pointer to an AVClass struct
4144 4144
  * @param[in] msg string containing an optional message, or NULL if no message
4145 4145
  */
4146
-void av_log_ask_for_sample(void *avc, const char *msg, ...);
4146
+void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
4147 4147
 
4148 4148
 /**
4149 4149
  * Register the hardware accelerator hwaccel.
... ...
@@ -284,11 +284,7 @@ attribute_deprecated int64_t url_fsize(AVIOContext *s);
284 284
 #define URL_EOF (-1)
285 285
 attribute_deprecated int url_fgetc(AVIOContext *s);
286 286
 attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
287
-#ifdef __GNUC__
288
-attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
289
-#else
290
-attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
291
-#endif
287
+attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
292 288
 attribute_deprecated void put_flush_packet(AVIOContext *s);
293 289
 attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
294 290
 attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size);
... ...
@@ -463,11 +459,7 @@ static av_always_inline int64_t avio_tell(AVIOContext *s)
463 463
 int64_t avio_size(AVIOContext *s);
464 464
 
465 465
 /** @warning currently size is limited */
466
-#ifdef __GNUC__
467
-int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
468
-#else
469
-int avio_printf(AVIOContext *s, const char *fmt, ...);
470
-#endif
466
+int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
471 467
 
472 468
 void avio_flush(AVIOContext *s);
473 469
 
... ...
@@ -108,7 +108,7 @@ uint64_t ff_ntp_time(void);
108 108
  */
109 109
 int ff_url_join(char *str, int size, const char *proto,
110 110
                 const char *authorization, const char *hostname,
111
-                int port, const char *fmt, ...);
111
+                int port, const char *fmt, ...) av_printf_format(7, 8);
112 112
 
113 113
 /**
114 114
  * Append the media-specific SDP fragment for the media stream c
... ...
@@ -86,7 +86,7 @@ int rtp_set_remote_url(URLContext *h, const char *uri)
86 86
  * "http://host:port/path?option1=val1&option2=val2...
87 87
  */
88 88
 
89
-static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
89
+static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)
90 90
 {
91 91
     char buf1[1024];
92 92
     va_list ap;
... ...
@@ -22,6 +22,7 @@
22 22
 #define AVUTIL_AVSTRING_H
23 23
 
24 24
 #include <stddef.h>
25
+#include "attributes.h"
25 26
 
26 27
 /**
27 28
  * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to
... ...
@@ -107,7 +108,7 @@ size_t av_strlcat(char *dst, const char *src, size_t size);
107 107
  * @return the length of the string that would have been generated
108 108
  *  if enough space had been available
109 109
  */
110
-size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
110
+size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
111 111
 
112 112
 /**
113 113
  * Convert a number to a av_malloced string.
... ...
@@ -23,6 +23,7 @@
23 23
 
24 24
 #include <stdarg.h>
25 25
 #include "avutil.h"
26
+#include "attributes.h"
26 27
 
27 28
 /**
28 29
  * Describe the class of an AVClass context structure. That is an
... ...
@@ -129,11 +130,7 @@ typedef struct {
129 129
  * subsequent arguments are converted to output.
130 130
  * @see av_vlog
131 131
  */
132
-#ifdef __GNUC__
133
-void av_log(void *avcl, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
134
-#else
135
-void av_log(void *avcl, int level, const char *fmt, ...);
136
-#endif
132
+void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
137 133
 
138 134
 void av_vlog(void *avcl, int level, const char *fmt, va_list);
139 135
 int av_log_get_level(void);