libubox: add format string checking to ulog()
authorKristupas Savickas <savickas.kristupas@gmail.com>
Thu, 6 Jun 2019 18:28:32 +0000 (21:28 +0300)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 16 Jun 2019 14:29:47 +0000 (16:29 +0200)
This offers an increased level of security, as the arguments will be
checked for validity against the format string at compile time. The
format attribute is supported by both GCC and Clang, so there shouldn't
be any portability issues.

Signed-off-by: Kristupas Savickas <savickas.kristupas@gmail.com>
ulog.h

diff --git a/ulog.h b/ulog.h
index 4818b1a8b5dfb8121352a4e625fc80e4ee662c22..46d3c77da9c24d8aa355631f61f6d20abfc11a44 100644 (file)
--- a/ulog.h
+++ b/ulog.h
@@ -32,7 +32,8 @@ void ulog_close(void);
 
 void ulog_threshold(int threshold);
 
-void ulog(int priority, const char *fmt, ...);
+void ulog(int priority, const char *fmt, ...)
+       __attribute__ ((format (printf, 2, 3)));
 
 #define ULOG_INFO(fmt, ...) ulog(LOG_INFO, fmt, ## __VA_ARGS__)
 #define ULOG_NOTE(fmt, ...) ulog(LOG_NOTICE, fmt, ## __VA_ARGS__)