From 1a3c55d7ea2daea8a2f232518d304501294ca36b Mon Sep 17 00:00:00 2001 From: Otto Date: Wed, 27 Jan 2021 15:21:59 +0100 Subject: [PATCH] Add a signedness check for time_t --- configure.ac | 4 +- m4/ax_check_sign.m4 | 54 +++++++++++++++++++++++++++ pdns/dnsdistdist/configure.ac | 3 ++ pdns/dnsdistdist/m4/ax_check_sign.m4 | 1 + pdns/recursordist/configure.ac | 3 ++ pdns/recursordist/m4/ax_check_sign.m4 | 1 + 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 m4/ax_check_sign.m4 create mode 120000 pdns/dnsdistdist/m4/ax_check_sign.m4 create mode 120000 pdns/recursordist/m4/ax_check_sign.m4 diff --git a/configure.ac b/configure.ac index 3922e85831..9d225cfc63 100644 --- a/configure.ac +++ b/configure.ac @@ -28,7 +28,9 @@ AC_LANG([C++]) AX_COMPILE_CHECK_SIZEOF(time_t) AS_IF([test $ac_size -lt 8], [AC_MSG_ERROR([size of time_t is $ac_size, which is not large enough to fix the y2k38 bug])]) - +AX_CHECK_SIGN([time_t], [:], [AC_MSG_ERROR([time_t is unsigned, PowerDNS code relies on it being signed])], [ + #include +]) PDNS_CHECK_BISON PDNS_CHECK_FLEX diff --git a/m4/ax_check_sign.m4 b/m4/ax_check_sign.m4 new file mode 100644 index 0000000000..bc2c3f034c --- /dev/null +++ b/m4/ax_check_sign.m4 @@ -0,0 +1,54 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_sign.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_SIGN (TYPE, [ACTION-IF-SIGNED], [ACTION-IF-UNSIGNED], [INCLUDES]) +# +# DESCRIPTION +# +# Checks whether TYPE is signed or not. If no INCLUDES are specified, the +# default includes are used. If ACTION-IF-SIGNED is given, it is +# additional shell code to execute when the type is signed. If +# ACTION-IF-UNSIGNED is given, it is executed when the type is unsigned. +# +# This macro assumes that the type exists. Therefore the existence of the +# type should be checked before calling this macro. For example: +# +# AC_CHECK_HEADERS([wchar.h]) +# AC_CHECK_TYPE([wchar_t],,[ AC_MSG_ERROR([Type wchar_t not found.]) ]) +# AX_CHECK_SIGN([wchar_t], +# [ AC_DEFINE(WCHAR_T_SIGNED, 1, [Define if wchar_t is signed]) ], +# [ AC_DEFINE(WCHAR_T_UNSIGNED, 1, [Define if wchar_t is unsigned]) ], [ +# #ifdef HAVE_WCHAR_H +# #include +# #endif +# ]) +# +# LICENSE +# +# Copyright (c) 2008 Ville Laurikari +# +# 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 7 + +AU_ALIAS([VL_CHECK_SIGN], [AX_CHECK_SIGN]) +AC_DEFUN([AX_CHECK_SIGN], [ + typename=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g"` + AC_CACHE_CHECK([whether $1 is signed], ax_cv_decl_${typename}_signed, [ + AC_TRY_COMPILE([$4], + [ int foo @<:@ 1 - 2 * !((($1) -1) < 0) @:>@ ], + [ eval "ax_cv_decl_${typename}_signed=\"yes\"" ], + [ eval "ax_cv_decl_${typename}_signed=\"no\"" ])]) + symbolname=`echo $1 | sed "s/@<:@^a-zA-Z0-9_@:>@/_/g" | tr "a-z" "A-Z"` + if eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"yes\""; then + $2 + elif eval "test \"\${ax_cv_decl_${typename}_signed}\" = \"no\""; then + $3 + fi +])dnl diff --git a/pdns/dnsdistdist/configure.ac b/pdns/dnsdistdist/configure.ac index cd8b4c8b40..bcc4db07e6 100644 --- a/pdns/dnsdistdist/configure.ac +++ b/pdns/dnsdistdist/configure.ac @@ -11,6 +11,9 @@ AC_LANG([C++]) AX_COMPILE_CHECK_SIZEOF(time_t) AS_IF([test $ac_size -lt 8], [AC_MSG_ERROR([size of time_t is $ac_size, which is not large enough to fix the y2k38 bug])]) +AX_CHECK_SIGN([time_t], [:], [AC_MSG_ERROR([time_t is unsigned, PowerDNS code relies on it being signed])], [ + #include +]) AC_DEFINE([DNSDIST], [1], [This is dnsdist] diff --git a/pdns/dnsdistdist/m4/ax_check_sign.m4 b/pdns/dnsdistdist/m4/ax_check_sign.m4 new file mode 120000 index 0000000000..1f2e120839 --- /dev/null +++ b/pdns/dnsdistdist/m4/ax_check_sign.m4 @@ -0,0 +1 @@ +../../../m4/ax_check_sign.m4 \ No newline at end of file diff --git a/pdns/recursordist/configure.ac b/pdns/recursordist/configure.ac index 0e835daeda..7ed55d09c7 100644 --- a/pdns/recursordist/configure.ac +++ b/pdns/recursordist/configure.ac @@ -27,6 +27,9 @@ AC_LANG([C++]) AX_COMPILE_CHECK_SIZEOF(time_t) AS_IF([test $ac_size -lt 8], [AC_MSG_ERROR([size of time_t is $ac_size, which is not large enough to fix the y2k38 bug])]) +AX_CHECK_SIGN([time_t], [:], [AC_MSG_ERROR([time_t is unsigned, PowerDNS code relies on it being signed])], [ + #include +]) AC_DEFINE([RECURSOR], [1], [This is the PowerDNS Recursor] diff --git a/pdns/recursordist/m4/ax_check_sign.m4 b/pdns/recursordist/m4/ax_check_sign.m4 new file mode 120000 index 0000000000..1f2e120839 --- /dev/null +++ b/pdns/recursordist/m4/ax_check_sign.m4 @@ -0,0 +1 @@ +../../../m4/ax_check_sign.m4 \ No newline at end of file -- 2.47.3