Update hardening rules.
authorBrian Aker <brian@tangent.org>
Wed, 5 Sep 2012 05:20:56 +0000 (01:20 -0400)
committerBrian Aker <brian@tangent.org>
Wed, 5 Sep 2012 05:20:56 +0000 (01:20 -0400)
.bzrignore
m4/ax_harden_compiler_flags.m4
m4/ax_pthread_timedjoin_np.m4 [new file with mode: 0644]
m4/have_cinttypes.m4
m4/have_libpq.m4 [new file with mode: 0644]
m4/hiredis.m4 [new file with mode: 0644]
m4/uuid.m4 [new file with mode: 0644]

index 6e70eae1a5b1085592bc989d5fbc0609ca17f670..ca98e6ef49486139dc10dc8087bf45013678e545 100644 (file)
@@ -150,3 +150,4 @@ tests/testudp
 tests/var/
 tmp_chroot
 unittests/unittests
+m4/.git
index 65cfdf5fb4d832cbec56394f8d0ce7a6e47617aa..2b06120152289a6c16958bcf5ecd986a51af24be 100644 (file)
@@ -8,7 +8,7 @@
 #
 # DESCRIPTION
 #
-#   Any compiler flag that "hardens" or tests code.
+#   Any compiler flag that "hardens" or tests code. C99 is assumed.
 #
 #   NOTE: Implementation based on AX_APPEND_FLAG.
 #
 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 #  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+# The Following flags are not checked for
+# -Wdeclaration-after-statement is counter to C99
+
 #serial 1
 
 AC_DEFUN([AX_HARDEN_COMPILER_FLAGS],
 [AC_REQUIRE([AX_APPEND_COMPILE_FLAGS])
 AC_REQUIRE([AX_CHECK_LINK_FLAG])
+AC_LANG_PUSH([C])
+AX_APPEND_COMPILE_FLAGS([-O2])
+AX_APPEND_COMPILE_FLAGS([-Werror])
+AX_APPEND_COMPILE_FLAGS([-Wall])
+AX_APPEND_COMPILE_FLAGS([-Wextra])
+AX_APPEND_COMPILE_FLAGS([-std=c99])
+AX_APPEND_COMPILE_FLAGS([-Wbad-function-cast])
+AX_APPEND_COMPILE_FLAGS([-Wmissing-prototypes])
+AX_APPEND_COMPILE_FLAGS([-Wnested-externs])
+AX_APPEND_COMPILE_FLAGS([-Wold-style-definition])
+AX_APPEND_COMPILE_FLAGS([-Woverride-init])
+AX_APPEND_COMPILE_FLAGS([-Wstrict-prototypes])
+AC_LANG_POP
+AC_LANG_PUSH([C++])
 AX_APPEND_COMPILE_FLAGS([-O2])
 AX_APPEND_COMPILE_FLAGS([-Werror])
 AX_APPEND_COMPILE_FLAGS([-Wall])
@@ -61,20 +78,18 @@ AX_APPEND_COMPILE_FLAGS([--paramssp-buffer-size=1])
 AX_APPEND_COMPILE_FLAGS([-D_FORTIFY_SOURCE=2])
 AX_APPEND_COMPILE_FLAGS([-Waddress])
 AX_APPEND_COMPILE_FLAGS([-Warray-bounds])
-AX_APPEND_COMPILE_FLAGS([-Wbad-function-cast])
 AX_APPEND_COMPILE_FLAGS([-Wchar-subscripts])
 AX_APPEND_COMPILE_FLAGS([-Wcomment])
-AX_APPEND_COMPILE_FLAGS([-Wdeclaration-after-statement])
+AX_APPEND_COMPILE_FLAGS([-Wctor-dtor-privacy])
 AX_APPEND_COMPILE_FLAGS([-Wfloat-equal])
 AX_APPEND_COMPILE_FLAGS([-Wformat=2])
+AX_APPEND_COMPILE_FLAGS([-Wlong-long])
 AX_APPEND_COMPILE_FLAGS([-Wmaybe-uninitialized])
 AX_APPEND_COMPILE_FLAGS([-Wmissing-field-initializers])
 AX_APPEND_COMPILE_FLAGS([-Wmissing-noreturn])
-AX_APPEND_COMPILE_FLAGS([-Wmissing-prototypes])
-AX_APPEND_COMPILE_FLAGS([-Wnested-externs])
+AX_APPEND_COMPILE_FLAGS([-Wnon-virtual-dtor])
 AX_APPEND_COMPILE_FLAGS([-Wnormalized=id])
-AX_APPEND_COMPILE_FLAGS([-Wold-style-definition])
-AX_APPEND_COMPILE_FLAGS([-Woverride-init])
+AX_APPEND_COMPILE_FLAGS([-Woverloaded-virtual])
 AX_APPEND_COMPILE_FLAGS([-Wpointer-arith])
 AX_APPEND_COMPILE_FLAGS([-Wredundant-decls])
 AX_APPEND_COMPILE_FLAGS([-Wshadow])
@@ -82,7 +97,6 @@ AX_APPEND_COMPILE_FLAGS([-Wshorten-64-to-32])
 AX_APPEND_COMPILE_FLAGS([-Wsign-compare])
 AX_APPEND_COMPILE_FLAGS([-Wstack-protector])
 AX_APPEND_COMPILE_FLAGS([-Wstrict-overflow=1])
-AX_APPEND_COMPILE_FLAGS([-Wstrict-prototypes])
 AX_APPEND_COMPILE_FLAGS([-Wswitch-enum])
 AX_APPEND_COMPILE_FLAGS([-Wundef])
 AX_APPEND_COMPILE_FLAGS([-Wunused-result])
@@ -94,4 +108,5 @@ AX_APPEND_COMPILE_FLAGS([-fwrapv])
 AX_APPEND_COMPILE_FLAGS([-ggdb])
 AX_CHECK_LINK_FLAG([-Werror])
 AX_CHECK_LINK_FLAG([-z relro -z now])
+AC_LANG_POP
 ])dnl AX_HARDEN_COMPILER_FLAGS
diff --git a/m4/ax_pthread_timedjoin_np.m4 b/m4/ax_pthread_timedjoin_np.m4
new file mode 100644 (file)
index 0000000..833b284
--- /dev/null
@@ -0,0 +1,48 @@
+# ===========================================================================
+# http://
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LIB_UUID
+#
+# DESCRIPTION
+#
+#   Check for pthread_timedjoin_np support.
+#
+# LICENSE
+#
+#   Copyright (c) 2012 Brian Aker <brian@tangent.org>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 2
+
+AC_DEFUN([AX_PTHREAD_TIMEDJOIN_NP], [
+    AC_CACHE_CHECK([check for pthread_timedjoin_np], [ax_cv_pthread_timedjoin_np], [
+      save_LDFLAGS="$LDFLAGS"
+      LDFLAGS="$PTHREAD_LIBS"
+      AC_LANG_PUSH([C])
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([
+#include <uuid/uuid.h>
+      ], [
+      uuid_t out;
+      pthread_timedjoin_np(out);
+      ]), [ax_cv_pthread_timedjoin_np=yes ], [ax_cv_pthread_timedjoin_np=no ]
+      ])
+
+    AC_LANG_POP
+     LDFLAGS="$save_LDFLAGS"
+
+    ])
+
+    AS_IF([test "$ax_cv_pthread_timedjoin_np" = yes],[
+      AC_DEFINE(HAVE_PTHREAD_TIMEDJOIN_NP,[1],[Define if pthread_timedjoin_np is present in pthread.h.])],[
+      AC_DEFINE(HAVE_PTHREAD_TIMEDJOIN_NP,[0],[Define if pthread_timedjoin_np is present in pthread.h.])
+    ])
+])
+
index b28c74ed5545c1247d0aaff239ee1d843a8f1b1e..bcfea1c35c91c9303cbf538bcc63db4d06108b5e 100644 (file)
@@ -1,4 +1,3 @@
-# vim:ft=m4
 # ===========================================================================
 #     http://tangent.org/
 # ===========================================================================
diff --git a/m4/have_libpq.m4 b/m4/have_libpq.m4
new file mode 100644 (file)
index 0000000..5617e30
--- /dev/null
@@ -0,0 +1,23 @@
+dnl  Copyright (C) 2011 Brian Aker (brian@tangent.org)
+
+AC_DEFUN([AX_HAVE_LIBPQ],[
+  AC_ARG_ENABLE([libpq],
+    [AS_HELP_STRING([--disable-libpq],
+    [Build with libpq, ie Postgres, support @<:@default=on@:>@])],
+      [ac_cv_libpq="$enableval"],
+      [ac_cv_libpq="yes"])
+
+  AC_REQUIRE([AX_LIB_POSTGRESQL])
+
+  AS_IF([test "x$ac_cv_libpq" = "xyes" -a "x$found_postgresql" = "xyes"],
+    [
+      AC_DEFINE([HAVE_LIBPQ], [ 1 ], [Enable libpq support])
+    ],
+    [
+      AC_DEFINE([HAVE_LIBPQ], [ 0 ], [Enable libpq support])
+      # if --enable-libpq, but no Postgres, force --disable-libpq
+      ac_cv_libpq="no"
+    ])
+
+  AM_CONDITIONAL(HAVE_LIBPQ, [test "x$ac_cv_libpq" = "xyes"])
+])
diff --git a/m4/hiredis.m4 b/m4/hiredis.m4
new file mode 100644 (file)
index 0000000..0680417
--- /dev/null
@@ -0,0 +1,34 @@
+dnl  Copyright (C) 2011 Brian Aker (brian@tangent.org)
+
+AC_DEFUN([_SEARCH_LIBHIREDIS],[
+  AC_REQUIRE([AX_CHECK_LIBRARY])
+
+  AS_IF([test "x$ac_enable_hires" = "xyes"],[
+        AX_CHECK_LIBRARY([LIBHIREDIS], [hiredis/hiredis.h], [hiredis],
+                         [
+                         LIBHIREDIS_LDFLAGS="-lhiredis"
+                         AC_DEFINE([HAVE_HIREDIS], [1], [If Hiredis available])
+                         ],
+                         [
+                         AC_DEFINE([HAVE_HIREDIS], [0], [If Hiredis is available])
+                         ac_enable_hires="no"
+                         ])
+
+        ],
+        [
+        AC_DEFINE([HAVE_HIREDIS], [0], [If Hiredis is available])
+        ])
+
+  AM_CONDITIONAL(HAVE_HIREDIS, [test "x$ac_cv_lib_hiredis_main" = "xyes"])
+  ])
+
+AC_DEFUN([AX_HAVE_LIBHIREDIS],[
+
+  AC_ARG_ENABLE([hires],
+    [AS_HELP_STRING([--disable-hires],
+      [Build with hires support @<:@default=on@:>@])],
+    [ac_enable_hires="$enableval"],
+    [ac_enable_hires="yes"])
+
+  _SEARCH_LIBHIREDIS
+])
diff --git a/m4/uuid.m4 b/m4/uuid.m4
new file mode 100644 (file)
index 0000000..9fc0cf3
--- /dev/null
@@ -0,0 +1,46 @@
+# ===========================================================================
+# http://
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LIB_UUID
+#
+# DESCRIPTION
+#
+#   Check for uuid, and uuid_generate_time_safe support.
+#
+# LICENSE
+#
+#   Copyright (c) 2012 Brian Aker <brian@tangent.org>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 2
+
+AC_DEFUN([AX_UUID_GENERATE_TIME_SAFE], [
+    AC_CACHE_CHECK([check for uuid_generate_time_safe], [ax_cv_uuid_generate_time_safe], [
+      save_LDFLAGS="$LDFLAGS"
+      LDFLAGS="-luuid"
+      AC_LANG_PUSH([C])
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([
+#include <uuid/uuid.h>
+      ], [
+      uuid_t out;
+      uuid_generate_time_safe(out);
+      ]), [ax_cv_uuid_generate_time_safe=yes ], [ax_cv_uuid_generate_time_safe=no ]
+      ])
+
+    AC_LANG_POP
+    LDFLAGS="$save_LDFLAGS"
+    ])
+
+  AS_IF([test "$ax_cv_uuid_generate_time_safe" = yes],[
+    AC_DEFINE(HAVE_UUID_GENERATE_TIME_SAFE,[1],[Define if uuid_generate_time_safe is present in uuid/uuid.h.])],[
+    AC_DEFINE(HAVE_UUID_GENERATE_TIME_SAFE,[0],[Define if uuid_generate_time_safe is present in uuid/uuid.h.])
+  ])
+])