mailing list of musl libc
 help / color / mirror / code / Atom feed
* [RFC] Add format attribute to syslog functions
@ 2015-11-22 14:12 Hauke Mehrtens
  0 siblings, 0 replies; only message in thread
From: Hauke Mehrtens @ 2015-11-22 14:12 UTC (permalink / raw)
  To: musl; +Cc: Hauke Mehrtens

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@hauke-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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-22 14:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-22 14:12 [RFC] Add format attribute to syslog functions Hauke Mehrtens

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).