From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8927 Path: news.gmane.org!not-for-mail From: Hauke Mehrtens Newsgroups: gmane.linux.lib.musl.general Subject: [RFC] Add format attribute to syslog functions Date: Sun, 22 Nov 2015 15:12:00 +0100 Message-ID: <1448201520-8969-1-git-send-email-hauke@hauke-m.de> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1448201553 1507 80.91.229.3 (22 Nov 2015 14:12:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 22 Nov 2015 14:12:33 +0000 (UTC) Cc: Hauke Mehrtens To: musl@lists.openwall.com Original-X-From: musl-return-8940-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 22 15:12:27 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1a0VNT-0002Kc-2C for gllmg-musl@m.gmane.org; Sun, 22 Nov 2015 15:12:27 +0100 Original-Received: (qmail 9597 invoked by uid 550); 22 Nov 2015 14:12:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9529 invoked from network); 22 Nov 2015 14:12:16 -0000 X-Mailer: git-send-email 2.6.2 X-Spam-Status: No, score=0.0 required=7.0 tests=UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on hauke-m.de Xref: news.gmane.org gmane.linux.lib.musl.general:8927 Archived-At: 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 --- 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 -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