Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1448201520-8969-1-git-send-email-hauke@hauke-m.de>
Date: Sun, 22 Nov 2015 15:12:00 +0100
From: Hauke Mehrtens <hauke@...ke-m.de>
To: musl@...ts.openwall.com
Cc: Hauke Mehrtens <hauke@...ke-m.de>
Subject: [RFC] Add format attribute to syslog functions

GCC and Clang are able to check the format arguments given to a
function and warn the user if there is a error in the format arguments
or if there is a potential uncontrolled format string security problem
in the code. GCC does this automatically for some functions like
printf(), but it is also possible to annotate other functions in a way
that it will check them too. This feature is used by glibc for many
functions. This patch adds it to the syslog functions in musl, but it
could probably be added to more functions in musl.

The documentation from gcc is here:
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bformat_007d-function-attribute-3170

The documentation from Clang is here:
http://clang.llvm.org/docs/AttributeReference.html#format-gnu-format

Signed-off-by: Hauke Mehrtens <hauke@...ke-m.de>
---
 include/syslog.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/syslog.h b/include/syslog.h
index 5b4d296..56cdaaf 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -59,13 +59,21 @@ extern "C" {
 void closelog (void);
 void openlog (const char *, int, int);
 int setlogmask (int);
-void syslog (int, const char *, ...);
+void syslog (int, const char *, ...)
+#if __GNUC__ >= 3
+__attribute__ ((format (printf, 2, 3)))
+#endif
+;
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define _PATH_LOG "/dev/log"
 #define __NEED_va_list
 #include <bits/alltypes.h>
-void vsyslog (int, const char *, va_list);
+void vsyslog (int, const char *, va_list)
+#if __GNUC__ >= 3
+__attribute__ ((format (printf, 2, 0)))
+#endif
+;
 #if defined(SYSLOG_NAMES)
 #define	INTERNAL_NOPRI 0x10
 #define	INTERNAL_MARK (LOG_NFACILITIES<<3)
-- 
2.6.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.