>From ee2cfd16d12e11d4878d8137b958e797bc2228a3 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Thu, 23 May 2013 13:14:37 +0200 Subject: [PATCH 01/16] Enable printf format string checking https://fedorahosted.org/sssd/ticket/1945 --- configure.ac | 18 ++++++++++++++++++ src/util/util.h | 14 ++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index b9b72e3d7cd3adf1bd127e6ae9546a460ee0055e..abde94774fb3d4e60302ff74ad4e9829550cfcc7 100644 --- a/configure.ac +++ b/configure.ac @@ -264,6 +264,24 @@ if test x"$sss_client_cv_attribute_destructor" = xyes ; then [whether compiler supports __attribute__((destructor))]) fi +AC_CACHE_CHECK([whether compiler supports __attribute__((format))], + sss_client_cv_attribute_format, + [AC_COMPILE_IFELSE( + [AC_LANG_SOURCE( + [void debug_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));] + )], + [sss_client_cv_attribute_format=yes], + [ + AC_MSG_RESULT([no]) + AC_MSG_WARN([compiler does NOT support __attribute__((format))]) + ]) + ]) + +if test x"$sss_client_cv_attribute_format" = xyes ; then + AC_DEFINE(HAVE_FUNCTION_ATTRIBUTE_FORMAT, 1, + [whether compiler supports __attribute__((format))]) +fi + PKG_CHECK_MODULES([CHECK], [check >= 0.9.5], [have_check=1], [have_check=]) if test x$have_check = x; then AC_MSG_WARN([Without the 'CHECK' libraries, you will be unable to run all tests in the 'make check' suite]) diff --git a/src/util/util.h b/src/util/util.h index 5acc67bec7ee94b85963d04f5bfcca017cf87abd..c328f7e9fb6d4bbd8667d171ccd0e593d1f0e70f 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -54,13 +54,19 @@ #define CLEAR_MC_FLAG "clear_mc_flag" +#ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT +#define SSS_ATTRIBUTE_PRINTF(a1, a2) __attribute__ ((format (printf, a1, a2))) +#else +#define SSS_ATTRIBUTE_PRINTF(a1, a2) +#endif + extern const char *debug_prg_name; extern int debug_level; extern int debug_timestamps; extern int debug_microseconds; extern int debug_to_file; extern const char *debug_log_file; -void debug_fn(const char *format, ...); +void debug_fn(const char *format, ...) SSS_ATTRIBUTE_PRINTF(1, 2); int debug_get_level(int old_level); int debug_convert_old_level(int old_level); errno_t set_debug_file_from_fd(const int fd); @@ -128,7 +134,7 @@ errno_t set_debug_file_from_fd(const int fd); memcpy(__debug_macro_datetime, ctime(&__debug_macro_tv.tv_sec), 19); \ __debug_macro_datetime[19] = '\0'; \ if (debug_microseconds) { \ - debug_fn("(%s:%.6d %d) [%s] [%s] (%#.4x): ", \ + debug_fn("(%s:%.6ld %d) [%s] [%s] (%#.4x): ", \ __debug_macro_datetime, __debug_macro_tv.tv_usec, \ __debug_macro_year, debug_prg_name, \ __FUNCTION__, __debug_macro_newlevel); \ @@ -169,7 +175,7 @@ errno_t set_debug_file_from_fd(const int fd); memcpy(__debug_macro_datetime, ctime(&__debug_macro_tv.tv_sec), 19); \ __debug_macro_datetime[19] = '\0'; \ if (debug_microseconds) { \ - debug_fn("(%s:%.6d %d) [%s] [%s] (%#.4x): %s\n", \ + debug_fn("(%s:%.6ld %d) [%s] [%s] (%#.4x): %s\n", \ __debug_macro_datetime, __debug_macro_tv.tv_usec, \ __debug_macro_year, debug_prg_name, \ function, __debug_macro_newlevel, message); \ @@ -292,7 +298,7 @@ void talloc_log_fn(const char *msg); #define SSS_LOG_INFO 6 /* informational */ #define SSS_LOG_DEBUG 7 /* debug-level messages */ -void sss_log(int priority, const char *format, ...); +void sss_log(int priority, const char *format, ...) SSS_ATTRIBUTE_PRINTF(2, 3); /* from server.c */ struct main_context { -- 1.8.3.1