[FFmpeg-cvslog] Use av_printf_format to check the usage of printf style functions

Martin Storsjö git at videolan.org
Fri Jun 24 03:13:07 CEST 2011


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Jun 17 10:31:11 2011 +0300| [9abbe8cc136e7fbc69004df3f1de9d54c40d969d] | committer: Martin Storsjö

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 at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9abbe8cc136e7fbc69004df3f1de9d54c40d969d
---

 libavcodec/avcodec.h   |    2 +-
 libavformat/avio.h     |   12 ++----------
 libavformat/internal.h |    2 +-
 libavformat/rtpproto.c |    2 +-
 libavutil/avstring.h   |    3 ++-
 libavutil/log.h        |    7 ++-----
 6 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a70d8ad..e251db4 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4143,7 +4143,7 @@ void av_log_missing_feature(void *avc, const char *feature, int want_sample);
  * a pointer to an AVClass struct
  * @param[in] msg string containing an optional message, or NULL if no message
  */
-void av_log_ask_for_sample(void *avc, const char *msg, ...);
+void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
 
 /**
  * Register the hardware accelerator hwaccel.
diff --git a/libavformat/avio.h b/libavformat/avio.h
index e07e3c3..bb2d9f8 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -284,11 +284,7 @@ attribute_deprecated int64_t url_fsize(AVIOContext *s);
 #define URL_EOF (-1)
 attribute_deprecated int url_fgetc(AVIOContext *s);
 attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size);
-#ifdef __GNUC__
-attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
-#else
-attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...);
-#endif
+attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
 attribute_deprecated void put_flush_packet(AVIOContext *s);
 attribute_deprecated int url_open_dyn_buf(AVIOContext **s);
 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)
 int64_t avio_size(AVIOContext *s);
 
 /** @warning currently size is limited */
-#ifdef __GNUC__
-int avio_printf(AVIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
-#else
-int avio_printf(AVIOContext *s, const char *fmt, ...);
-#endif
+int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
 
 void avio_flush(AVIOContext *s);
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 7413b09..30faa00 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -108,7 +108,7 @@ uint64_t ff_ntp_time(void);
  */
 int ff_url_join(char *str, int size, const char *proto,
                 const char *authorization, const char *hostname,
-                int port, const char *fmt, ...);
+                int port, const char *fmt, ...) av_printf_format(7, 8);
 
 /**
  * Append the media-specific SDP fragment for the media stream c
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 1340665..dba1d35 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -86,7 +86,7 @@ int rtp_set_remote_url(URLContext *h, const char *uri)
  * "http://host:port/path?option1=val1&option2=val2...
  */
 
-static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
+static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)
 {
     char buf1[1024];
     va_list ap;
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index b40acf6..44ed89d 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -22,6 +22,7 @@
 #define AVUTIL_AVSTRING_H
 
 #include <stddef.h>
+#include "attributes.h"
 
 /**
  * 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);
  * @return the length of the string that would have been generated
  *  if enough space had been available
  */
-size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...);
+size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4);
 
 /**
  * Convert a number to a av_malloced string.
diff --git a/libavutil/log.h b/libavutil/log.h
index c823a76..c1d9a6c 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -23,6 +23,7 @@
 
 #include <stdarg.h>
 #include "avutil.h"
+#include "attributes.h"
 
 /**
  * Describe the class of an AVClass context structure. That is an
@@ -129,11 +130,7 @@ typedef struct {
  * subsequent arguments are converted to output.
  * @see av_vlog
  */
-#ifdef __GNUC__
-void av_log(void *avcl, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
-#else
-void av_log(void *avcl, int level, const char *fmt, ...);
-#endif
+void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
 
 void av_vlog(void *avcl, int level, const char *fmt, va_list);
 int av_log_get_level(void);



More information about the ffmpeg-cvslog mailing list