From c138111a3c27863308b6552a5527a9e821a3dc11 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 May 2020 17:05:30 -0700 Subject: Update to rra-c-util 8.2 and C TAP Harness 4.7 Update to rra-c-util 8.2: * Implement explicit_bzero with memset if it is not available. * Reformat all C source using clang-format 10. * Work around Test::Strict not skipping .git directories. * Fix warnings with perltidy 20190601 and Perl::Critic 1.134. * Fix warnings with Clang 10, GCC 10, and the Clang static analyzer. Update to C TAP Harness 4.7: * Fix warnings with GCC 10. * Reformat all C source using clang-format 10. * Fixed malloc error checking in bstrndup. --- NEWS | 16 ++ m4/cc-flags.m4 | 6 +- m4/gssapi.m4 | 3 - m4/krb5.m4 | 38 ++--- perl/lib/Wallet/ACL.pm | 2 +- perl/lib/Wallet/ACL/Base.pm | 2 +- perl/lib/Wallet/ACL/External.pm | 2 +- perl/lib/Wallet/ACL/Krb5.pm | 2 +- perl/lib/Wallet/ACL/Krb5/Regex.pm | 2 +- perl/lib/Wallet/ACL/LDAP/Attribute.pm | 2 +- perl/lib/Wallet/ACL/LDAP/Attribute/Root.pm | 2 +- perl/lib/Wallet/ACL/Nested.pm | 2 +- perl/lib/Wallet/ACL/NetDB.pm | 2 +- perl/lib/Wallet/ACL/NetDB/Root.pm | 2 +- perl/lib/Wallet/Admin.pm | 2 +- perl/lib/Wallet/Config.pm | 2 +- perl/lib/Wallet/Database.pm | 2 +- perl/lib/Wallet/Kadmin.pm | 2 +- perl/lib/Wallet/Kadmin/AD.pm | 2 +- perl/lib/Wallet/Kadmin/Heimdal.pm | 2 +- perl/lib/Wallet/Kadmin/MIT.pm | 2 +- perl/lib/Wallet/Object/Base.pm | 2 +- perl/lib/Wallet/Object/Duo.pm | 2 +- perl/lib/Wallet/Object/File.pm | 2 +- perl/lib/Wallet/Object/Keytab.pm | 2 +- perl/lib/Wallet/Object/Password.pm | 2 +- perl/lib/Wallet/Object/WAKeyring.pm | 2 +- perl/lib/Wallet/Policy/Stanford.pm | 2 +- perl/lib/Wallet/Report.pm | 2 +- perl/lib/Wallet/Schema/Result/Acl.pm | 2 +- perl/lib/Wallet/Schema/Result/AclEntry.pm | 2 +- perl/lib/Wallet/Schema/Result/AclHistory.pm | 2 +- perl/lib/Wallet/Schema/Result/AclScheme.pm | 2 +- perl/lib/Wallet/Schema/Result/Duo.pm | 2 +- perl/lib/Wallet/Schema/Result/Enctype.pm | 6 +- perl/lib/Wallet/Schema/Result/Flag.pm | 2 +- perl/lib/Wallet/Schema/Result/KeytabEnctype.pm | 6 +- perl/lib/Wallet/Schema/Result/KeytabSync.pm | 6 +- perl/lib/Wallet/Schema/Result/Object.pm | 2 +- perl/lib/Wallet/Schema/Result/ObjectHistory.pm | 2 +- perl/lib/Wallet/Schema/Result/SyncTarget.pm | 2 +- perl/lib/Wallet/Schema/Result/Type.pm | 2 +- perl/lib/Wallet/Server.pm | 2 +- perl/t/docs/pod-spelling.t | 6 +- perl/t/docs/pod.t | 6 +- perl/t/style/minimum-version.t | 6 +- perl/t/style/strict.t | 50 ++++-- perl/t/verifier/ldap-attr.t | 7 +- perl/t/verifier/netdb.t | 11 +- portable/asprintf.c | 8 +- portable/krb5-extra.c | 38 ++--- portable/krb5-profile.c | 2 +- portable/krb5.h | 30 ++-- portable/macros.h | 24 +-- portable/mkstemp.c | 6 +- portable/reallocarray.c | 4 +- portable/setenv.c | 4 +- portable/snprintf.c | 35 +++- portable/stdbool.h | 34 ++-- portable/system.h | 32 ++-- portable/uio.h | 2 +- tests/data/cppcheck.supp | 31 +++- tests/data/fake-kadmin | 2 +- tests/docs/pod-spelling-t | 7 +- tests/docs/pod-t | 7 +- tests/docs/spdx-license-t | 35 ++-- tests/perl/minimum-version-t | 9 +- tests/perl/module-version-t | 16 +- tests/perl/strict-t | 7 +- tests/portable/snprintf-t.c | 43 +++-- tests/runtests.c | 187 +++++++++++---------- tests/style/obsolete-strings-t | 9 +- tests/tap/basic.c | 214 +++++++++++++++---------- tests/tap/basic.h | 43 +++-- tests/tap/kerberos.c | 9 +- tests/tap/kerberos.h | 26 +-- tests/tap/macros.h | 32 ++-- tests/tap/perl/Test/RRA.pm | 81 +++++++--- tests/tap/perl/Test/RRA/Automake.pm | 19 +-- tests/tap/perl/Test/RRA/Config.pm | 14 +- tests/tap/perl/Test/RRA/ModuleVersion.pm | 20 +-- tests/tap/process.c | 18 +-- tests/tap/process.h | 3 +- tests/tap/string.h | 2 +- tests/util/messages-krb5-t.c | 9 +- tests/util/messages-t.c | 34 ++-- tests/util/xmalloc-t | 37 ++--- tests/util/xmalloc.c | 12 +- util/messages-krb5.c | 2 +- util/messages.c | 56 +++---- util/xmalloc.c | 8 +- util/xmalloc.h | 22 +-- 92 files changed, 836 insertions(+), 636 deletions(-) diff --git a/NEWS b/NEWS index 2696d22..62c18bd 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,21 @@ User-Visible wallet Changes +wallet 1.5 (unreleased) + + Update to rra-c-util 8.2: + + * Implement explicit_bzero with memset if it is not available. + * Reformat all C source using clang-format 10. + * Work around Test::Strict not skipping .git directories. + * Fix warnings with perltidy 20190601 and Perl::Critic 1.134. + * Fix warnings with Clang 10, GCC 10, and the Clang static analyzer. + + Update to C TAP Harness 4.7: + + * Fix warnings with GCC 10. + * Reformat all C source using clang-format 10. + * Fixed malloc error checking in bstrndup. + wallet 1.4 (2018-06-03) Substantial improvements to Active Directory support: Add a diff --git a/m4/cc-flags.m4 b/m4/cc-flags.m4 index 8a5aa8a..9a749f7 100644 --- a/m4/cc-flags.m4 +++ b/m4/cc-flags.m4 @@ -14,7 +14,7 @@ dnl dnl The canonical version of this file is maintained in the rra-c-util dnl package, available at . dnl -dnl Copyright 2016-2018 Russ Allbery +dnl Copyright 2016-2020 Russ Allbery dnl Copyright 2006, 2009, 2016 dnl by Internet Systems Consortium, Inc. ("ISC") dnl @@ -36,7 +36,7 @@ dnl Used to build the result cache name. AC_DEFUN([_RRA_PROG_CC_FLAG_CACHE], [translit([rra_cv_compiler_c_$1], [-=+], [___])]) -dnl Check whether a given flag is supported by the complier. +dnl Check whether a given flag is supported by the compiler. AC_DEFUN([RRA_PROG_CC_FLAG], [AC_REQUIRE([AC_PROG_CC]) AC_MSG_CHECKING([if $CC supports $1]) @@ -61,7 +61,7 @@ dnl dnl -Wsign-conversion Too many fiddly changes for the benefit dnl -Wstack-protector Too many false positives from small buffers dnl -dnl Last checked against gcc 7.2.0 (2017-12-28). -D_FORTIFY_SOURCE=2 enables +dnl Last checked against gcc 9.2.1 (2019-09-01). -D_FORTIFY_SOURCE=2 enables dnl warn_unused_result attribute markings on glibc functions on Linux, which dnl catches a few more issues. Add -O2 because gcc won't find some warnings dnl without optimization turned on. diff --git a/m4/gssapi.m4 b/m4/gssapi.m4 index 5828b1b..462111b 100644 --- a/m4/gssapi.m4 +++ b/m4/gssapi.m4 @@ -12,9 +12,6 @@ dnl RRA_LIB_GSSAPI_SWITCH to set CPPFLAGS, LDFLAGS, and LIBS to include the dnl GSS-API libraries, saving the ecurrent values, and RRA_LIB_GSSAPI_RESTORE dnl to restore those settings to before the last RRA_LIB_GSSAPI_SWITCH. dnl -dnl Also provides RRA_INCLUDES_KRB5, which are the headers to include when -dnl probing the Kerberos library properties. -dnl dnl Depends on RRA_KRB5_CONFIG, RRA_ENABLE_REDUCED_DEPENDS, and dnl RRA_SET_LDFLAGS. dnl diff --git a/m4/krb5.m4 b/m4/krb5.m4 index 8d9db43..617c27b 100644 --- a/m4/krb5.m4 +++ b/m4/krb5.m4 @@ -50,6 +50,7 @@ dnl The canonical version of this file is maintained in the rra-c-util dnl package, available at . dnl dnl Written by Russ Allbery +dnl Copyright 2018 Russ Allbery dnl Copyright 2005-2011, 2013-2014 dnl The Board of Trustees of the Leland Stanford Junior University dnl @@ -139,26 +140,27 @@ dnl linkage. The single argument, if true, says to fail if Kerberos could not dnl be found. AC_DEFUN([_RRA_LIB_KRB5_REDUCED], [RRA_LIB_KRB5_SWITCH - AC_CHECK_LIB([krb5], [krb5_init_context], [KRB5_LIBS="-lkrb5"], + AC_CHECK_LIB([krb5], [krb5_init_context], + [KRB5_LIBS="-lkrb5" + LIBS="$KRB5_LIBS $LIBS" + _RRA_LIB_KRB5_CHECK_HEADER_KRB5 + AC_CHECK_FUNCS([krb5_get_error_message], + [AC_CHECK_FUNCS([krb5_free_error_message])], + [AC_CHECK_FUNCS([krb5_get_error_string], [], + [AC_CHECK_FUNCS([krb5_get_err_txt], [], + [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg], + [KRB5_LIBS="$KRB5_LIBS -lksvc" + AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1]) + AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [], + [RRA_INCLUDES_KRB5])], + [AC_CHECK_LIB([com_err], [com_err], + [KRB5_LIBS="$KRB5_LIBS -lcom_err"], + [AS_IF([test x"$1" = xtrue], + [AC_MSG_ERROR([cannot find usable com_err library])], + [KRB5_LIBS=""])]) + _RRA_LIB_KRB5_CHECK_HEADER_COM_ERR])])])])], [AS_IF([test x"$1" = xtrue], [AC_MSG_ERROR([cannot find usable Kerberos library])])]) - LIBS="$KRB5_LIBS $LIBS" - _RRA_LIB_KRB5_CHECK_HEADER_KRB5 - AC_CHECK_FUNCS([krb5_get_error_message], - [AC_CHECK_FUNCS([krb5_free_error_message])], - [AC_CHECK_FUNCS([krb5_get_error_string], [], - [AC_CHECK_FUNCS([krb5_get_err_txt], [], - [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg], - [KRB5_LIBS="$KRB5_LIBS -lksvc" - AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1]) - AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [], - [RRA_INCLUDES_KRB5])], - [AC_CHECK_LIB([com_err], [com_err], - [KRB5_LIBS="$KRB5_LIBS -lcom_err"], - [AS_IF([test x"$1" = xtrue], - [AC_MSG_ERROR([cannot find usable com_err library])], - [KRB5_LIBS=""])]) - _RRA_LIB_KRB5_CHECK_HEADER_COM_ERR])])])]) RRA_LIB_KRB5_RESTORE]) dnl Does the appropriate library checks for Kerberos linkage when we don't diff --git a/perl/lib/Wallet/ACL.pm b/perl/lib/Wallet/ACL.pm index 948b71c..58e33b4 100644 --- a/perl/lib/Wallet/ACL.pm +++ b/perl/lib/Wallet/ACL.pm @@ -20,7 +20,7 @@ use warnings; use DateTime; use Wallet::Object::Base; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Constructors diff --git a/perl/lib/Wallet/ACL/Base.pm b/perl/lib/Wallet/ACL/Base.pm index 320a731..1a33227 100644 --- a/perl/lib/Wallet/ACL/Base.pm +++ b/perl/lib/Wallet/ACL/Base.pm @@ -17,7 +17,7 @@ use 5.008; use strict; use warnings; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/External.pm b/perl/lib/Wallet/ACL/External.pm index 2285469..1dc1ea7 100644 --- a/perl/lib/Wallet/ACL/External.pm +++ b/perl/lib/Wallet/ACL/External.pm @@ -19,7 +19,7 @@ use Wallet::ACL::Base; use Wallet::Config; our @ISA = qw(Wallet::ACL::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/Krb5.pm b/perl/lib/Wallet/ACL/Krb5.pm index 3309274..88f8cd9 100644 --- a/perl/lib/Wallet/ACL/Krb5.pm +++ b/perl/lib/Wallet/ACL/Krb5.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL::Base; our @ISA = qw(Wallet::ACL::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/Krb5/Regex.pm b/perl/lib/Wallet/ACL/Krb5/Regex.pm index be6c5e1..d69ba60 100644 --- a/perl/lib/Wallet/ACL/Krb5/Regex.pm +++ b/perl/lib/Wallet/ACL/Krb5/Regex.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL::Krb5; our @ISA = qw(Wallet::ACL::Krb5); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/LDAP/Attribute.pm b/perl/lib/Wallet/ACL/LDAP/Attribute.pm index 65e0208..a3fb941 100644 --- a/perl/lib/Wallet/ACL/LDAP/Attribute.pm +++ b/perl/lib/Wallet/ACL/LDAP/Attribute.pm @@ -23,7 +23,7 @@ use Wallet::ACL::Base; use Wallet::Config; our @ISA = qw(Wallet::ACL::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/LDAP/Attribute/Root.pm b/perl/lib/Wallet/ACL/LDAP/Attribute/Root.pm index 5ebece6..89d4eba 100644 --- a/perl/lib/Wallet/ACL/LDAP/Attribute/Root.pm +++ b/perl/lib/Wallet/ACL/LDAP/Attribute/Root.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL::LDAP::Attribute; our @ISA = qw(Wallet::ACL::LDAP::Attribute); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/Nested.pm b/perl/lib/Wallet/ACL/Nested.pm index a6b6655..d3f11ec 100644 --- a/perl/lib/Wallet/ACL/Nested.pm +++ b/perl/lib/Wallet/ACL/Nested.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL::Base; our @ISA = qw(Wallet::ACL::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/NetDB.pm b/perl/lib/Wallet/ACL/NetDB.pm index c5fdc39..ead0429 100644 --- a/perl/lib/Wallet/ACL/NetDB.pm +++ b/perl/lib/Wallet/ACL/NetDB.pm @@ -21,7 +21,7 @@ use Wallet::ACL::Base; use Wallet::Config; our @ISA = qw(Wallet::ACL::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/ACL/NetDB/Root.pm b/perl/lib/Wallet/ACL/NetDB/Root.pm index 2dd1562..cb123c4 100644 --- a/perl/lib/Wallet/ACL/NetDB/Root.pm +++ b/perl/lib/Wallet/ACL/NetDB/Root.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL::NetDB; our @ISA = qw(Wallet::ACL::NetDB); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Interface diff --git a/perl/lib/Wallet/Admin.pm b/perl/lib/Wallet/Admin.pm index 707f410..630ac81 100644 --- a/perl/lib/Wallet/Admin.pm +++ b/perl/lib/Wallet/Admin.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL; use Wallet::Schema; -our $VERSION = '1.04'; +our $VERSION = '1.05'; # The last non-DBIx::Class version of Wallet::Schema. If a database has no # DBIx::Class versioning, we artificially install this version number before diff --git a/perl/lib/Wallet/Config.pm b/perl/lib/Wallet/Config.pm index 60f0e10..969ad9a 100644 --- a/perl/lib/Wallet/Config.pm +++ b/perl/lib/Wallet/Config.pm @@ -13,7 +13,7 @@ use 5.008; use strict; use warnings; -our $VERSION = '1.04'; +our $VERSION = '1.05'; # Path to the config file to load. our $PATH = $ENV{WALLET_CONFIG} || '/etc/wallet/wallet.conf'; diff --git a/perl/lib/Wallet/Database.pm b/perl/lib/Wallet/Database.pm index 83b8dfc..e98c85c 100644 --- a/perl/lib/Wallet/Database.pm +++ b/perl/lib/Wallet/Database.pm @@ -26,7 +26,7 @@ use Wallet::Config; use Wallet::Schema; our @ISA = qw(Wallet::Schema); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Core overrides diff --git a/perl/lib/Wallet/Kadmin.pm b/perl/lib/Wallet/Kadmin.pm index 150c188..02a3b54 100644 --- a/perl/lib/Wallet/Kadmin.pm +++ b/perl/lib/Wallet/Kadmin.pm @@ -19,7 +19,7 @@ use warnings; use Wallet::Config; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Utility functions for child classes diff --git a/perl/lib/Wallet/Kadmin/AD.pm b/perl/lib/Wallet/Kadmin/AD.pm index f2f86b9..6acebb9 100644 --- a/perl/lib/Wallet/Kadmin/AD.pm +++ b/perl/lib/Wallet/Kadmin/AD.pm @@ -26,7 +26,7 @@ use Wallet::Config; use Wallet::Kadmin; our @ISA = qw(Wallet::Kadmin); -our $VERSION = '1.04'; +our $VERSION = '1.05'; my $LDAP; diff --git a/perl/lib/Wallet/Kadmin/Heimdal.pm b/perl/lib/Wallet/Kadmin/Heimdal.pm index 57013de..1478936 100644 --- a/perl/lib/Wallet/Kadmin/Heimdal.pm +++ b/perl/lib/Wallet/Kadmin/Heimdal.pm @@ -22,7 +22,7 @@ use Wallet::Config; use Wallet::Kadmin; our @ISA = qw(Wallet::Kadmin); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Utility functions diff --git a/perl/lib/Wallet/Kadmin/MIT.pm b/perl/lib/Wallet/Kadmin/MIT.pm index 373d4cf..99d8ea8 100644 --- a/perl/lib/Wallet/Kadmin/MIT.pm +++ b/perl/lib/Wallet/Kadmin/MIT.pm @@ -23,7 +23,7 @@ use Wallet::Config; use Wallet::Kadmin; our @ISA = qw(Wallet::Kadmin); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # kadmin Interaction diff --git a/perl/lib/Wallet/Object/Base.pm b/perl/lib/Wallet/Object/Base.pm index bf535e9..ef4716c 100644 --- a/perl/lib/Wallet/Object/Base.pm +++ b/perl/lib/Wallet/Object/Base.pm @@ -22,7 +22,7 @@ use Date::Parse qw(str2time); use Text::Wrap qw(wrap); use Wallet::ACL; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Constructors diff --git a/perl/lib/Wallet/Object/Duo.pm b/perl/lib/Wallet/Object/Duo.pm index 1ec527e..1072e41 100644 --- a/perl/lib/Wallet/Object/Duo.pm +++ b/perl/lib/Wallet/Object/Duo.pm @@ -23,7 +23,7 @@ use Wallet::Config; use Wallet::Object::Base; our @ISA = qw(Wallet::Object::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; # Mappings from our types into what Duo calls the integration types. our %DUO_TYPES = ( diff --git a/perl/lib/Wallet/Object/File.pm b/perl/lib/Wallet/Object/File.pm index bef8981..6ad236e 100644 --- a/perl/lib/Wallet/Object/File.pm +++ b/perl/lib/Wallet/Object/File.pm @@ -23,7 +23,7 @@ use Wallet::Config; use Wallet::Object::Base; our @ISA = qw(Wallet::Object::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # File naming diff --git a/perl/lib/Wallet/Object/Keytab.pm b/perl/lib/Wallet/Object/Keytab.pm index 498e657..092daf7 100644 --- a/perl/lib/Wallet/Object/Keytab.pm +++ b/perl/lib/Wallet/Object/Keytab.pm @@ -22,7 +22,7 @@ use Wallet::Kadmin; use Wallet::Object::Base; our @ISA = qw(Wallet::Object::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Shared methods diff --git a/perl/lib/Wallet/Object/Password.pm b/perl/lib/Wallet/Object/Password.pm index 336aa9d..f124c43 100644 --- a/perl/lib/Wallet/Object/Password.pm +++ b/perl/lib/Wallet/Object/Password.pm @@ -23,7 +23,7 @@ use Wallet::Config; use Wallet::Object::File; our @ISA = qw(Wallet::Object::File); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # File naming diff --git a/perl/lib/Wallet/Object/WAKeyring.pm b/perl/lib/Wallet/Object/WAKeyring.pm index a64b376..923292d 100644 --- a/perl/lib/Wallet/Object/WAKeyring.pm +++ b/perl/lib/Wallet/Object/WAKeyring.pm @@ -24,7 +24,7 @@ use Wallet::Object::Base; use WebAuth 3.06 qw(WA_KEY_AES WA_AES_128); our @ISA = qw(Wallet::Object::Base); -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # File naming diff --git a/perl/lib/Wallet/Policy/Stanford.pm b/perl/lib/Wallet/Policy/Stanford.pm index 2c761bb..3aeea1c 100644 --- a/perl/lib/Wallet/Policy/Stanford.pm +++ b/perl/lib/Wallet/Policy/Stanford.pm @@ -26,7 +26,7 @@ our (@EXPORT_OK, $VERSION); # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - $VERSION = '1.04'; + $VERSION = '1.05'; @EXPORT_OK = qw(default_owner verify_name is_for_host); } diff --git a/perl/lib/Wallet/Report.pm b/perl/lib/Wallet/Report.pm index 151a285..d4add04 100644 --- a/perl/lib/Wallet/Report.pm +++ b/perl/lib/Wallet/Report.pm @@ -20,7 +20,7 @@ use warnings; use Wallet::ACL; use Wallet::Schema; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Constructor, destructor, and accessors diff --git a/perl/lib/Wallet/Schema/Result/Acl.pm b/perl/lib/Wallet/Schema/Result/Acl.pm index 9a73b18..b3836f9 100644 --- a/perl/lib/Wallet/Schema/Result/Acl.pm +++ b/perl/lib/Wallet/Schema/Result/Acl.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords ACL diff --git a/perl/lib/Wallet/Schema/Result/AclEntry.pm b/perl/lib/Wallet/Schema/Result/AclEntry.pm index 1737084..d84f5d4 100644 --- a/perl/lib/Wallet/Schema/Result/AclEntry.pm +++ b/perl/lib/Wallet/Schema/Result/AclEntry.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords ACL diff --git a/perl/lib/Wallet/Schema/Result/AclHistory.pm b/perl/lib/Wallet/Schema/Result/AclHistory.pm index 48aed49..db99b31 100644 --- a/perl/lib/Wallet/Schema/Result/AclHistory.pm +++ b/perl/lib/Wallet/Schema/Result/AclHistory.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; __PACKAGE__->load_components("InflateColumn::DateTime"); diff --git a/perl/lib/Wallet/Schema/Result/AclScheme.pm b/perl/lib/Wallet/Schema/Result/AclScheme.pm index abdd541..165c6ee 100644 --- a/perl/lib/Wallet/Schema/Result/AclScheme.pm +++ b/perl/lib/Wallet/Schema/Result/AclScheme.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; __PACKAGE__->load_components (qw//); diff --git a/perl/lib/Wallet/Schema/Result/Duo.pm b/perl/lib/Wallet/Schema/Result/Duo.pm index def9dce..0dedf8e 100644 --- a/perl/lib/Wallet/Schema/Result/Duo.pm +++ b/perl/lib/Wallet/Schema/Result/Duo.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords keytab enctype diff --git a/perl/lib/Wallet/Schema/Result/Enctype.pm b/perl/lib/Wallet/Schema/Result/Enctype.pm index 24fa897..433a38e 100644 --- a/perl/lib/Wallet/Schema/Result/Enctype.pm +++ b/perl/lib/Wallet/Schema/Result/Enctype.pm @@ -1,10 +1,10 @@ # Wallet schema for Kerberos encryption type. # # Written by Jon Robertson -# Copyright 2012, 2013 +# Copyright 2012-2013 # The Board of Trustees of the Leland Stanford Junior University # -# See LICENSE for licensing terms. +# SPDX-License-Identifier: MIT package Wallet::Schema::Result::Enctype; @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords Kerberos diff --git a/perl/lib/Wallet/Schema/Result/Flag.pm b/perl/lib/Wallet/Schema/Result/Flag.pm index 4ed8dcb..af352e2 100644 --- a/perl/lib/Wallet/Schema/Result/Flag.pm +++ b/perl/lib/Wallet/Schema/Result/Flag.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =head1 NAME diff --git a/perl/lib/Wallet/Schema/Result/KeytabEnctype.pm b/perl/lib/Wallet/Schema/Result/KeytabEnctype.pm index abb465e..0e30282 100644 --- a/perl/lib/Wallet/Schema/Result/KeytabEnctype.pm +++ b/perl/lib/Wallet/Schema/Result/KeytabEnctype.pm @@ -1,10 +1,10 @@ # Wallet schema for keytab enctype. # # Written by Jon Robertson -# Copyright 2012, 2013 +# Copyright 2012-2013 # The Board of Trustees of the Leland Stanford Junior University # -# See LICENSE for licensing terms. +# SPDX-License-Identifier: MIT package Wallet::Schema::Result::KeytabEnctype; @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords keytab enctype diff --git a/perl/lib/Wallet/Schema/Result/KeytabSync.pm b/perl/lib/Wallet/Schema/Result/KeytabSync.pm index 1939e74..676d8d6 100644 --- a/perl/lib/Wallet/Schema/Result/KeytabSync.pm +++ b/perl/lib/Wallet/Schema/Result/KeytabSync.pm @@ -1,10 +1,10 @@ # Wallet schema for keytab synchronization. # # Written by Jon Robertson -# Copyright 2012, 2013 +# Copyright 2012-2013 # The Board of Trustees of the Leland Stanford Junior University # -# See LICENSE for licensing terms. +# SPDX-License-Identifier: MIT package Wallet::Schema::Result::KeytabSync; @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords keytab diff --git a/perl/lib/Wallet/Schema/Result/Object.pm b/perl/lib/Wallet/Schema/Result/Object.pm index b4bc46f..3a25ed2 100644 --- a/perl/lib/Wallet/Schema/Result/Object.pm +++ b/perl/lib/Wallet/Schema/Result/Object.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; __PACKAGE__->load_components("InflateColumn::DateTime"); diff --git a/perl/lib/Wallet/Schema/Result/ObjectHistory.pm b/perl/lib/Wallet/Schema/Result/ObjectHistory.pm index c6c6225..e8eb25d 100644 --- a/perl/lib/Wallet/Schema/Result/ObjectHistory.pm +++ b/perl/lib/Wallet/Schema/Result/ObjectHistory.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; __PACKAGE__->load_components("InflateColumn::DateTime"); diff --git a/perl/lib/Wallet/Schema/Result/SyncTarget.pm b/perl/lib/Wallet/Schema/Result/SyncTarget.pm index ff6e3f3..134ab44 100644 --- a/perl/lib/Wallet/Schema/Result/SyncTarget.pm +++ b/perl/lib/Wallet/Schema/Result/SyncTarget.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =head1 NAME diff --git a/perl/lib/Wallet/Schema/Result/Type.pm b/perl/lib/Wallet/Schema/Result/Type.pm index a9238e6..7ffd03c 100644 --- a/perl/lib/Wallet/Schema/Result/Type.pm +++ b/perl/lib/Wallet/Schema/Result/Type.pm @@ -13,7 +13,7 @@ use warnings; use base 'DBIx::Class::Core'; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =for stopwords APIs diff --git a/perl/lib/Wallet/Server.pm b/perl/lib/Wallet/Server.pm index af0d8a8..959595e 100644 --- a/perl/lib/Wallet/Server.pm +++ b/perl/lib/Wallet/Server.pm @@ -21,7 +21,7 @@ use Wallet::ACL; use Wallet::Config; use Wallet::Schema; -our $VERSION = '1.04'; +our $VERSION = '1.05'; ############################################################################## # Utility methods diff --git a/perl/t/docs/pod-spelling.t b/perl/t/docs/pod-spelling.t index 94d7503..819aa69 100755 --- a/perl/t/docs/pod-spelling.t +++ b/perl/t/docs/pod-spelling.t @@ -6,6 +6,7 @@ # which can be found at . # # Written by Russ Allbery +# Copyright 2019 Russ Allbery # Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -29,15 +30,16 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib 't/lib'; -use Test::More; use Test::RRA qw(skip_unless_author use_prereq); +use Test::More; + # Only run this test for the module author since the required stopwords are # too sensitive to the exact spell-checking program and dictionary. skip_unless_author('Spelling tests'); diff --git a/perl/t/docs/pod.t b/perl/t/docs/pod.t index 5fcfcdf..e7d0231 100755 --- a/perl/t/docs/pod.t +++ b/perl/t/docs/pod.t @@ -6,6 +6,7 @@ # which can be found at . # # Written by Russ Allbery +# Copyright 2019 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -29,15 +30,16 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib 't/lib'; -use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); +use Test::More; + # Skip this test for normal user installs, although pod2man may still fail. skip_unless_automated('POD syntax tests'); diff --git a/perl/t/style/minimum-version.t b/perl/t/style/minimum-version.t index 7698c2b..861367d 100755 --- a/perl/t/style/minimum-version.t +++ b/perl/t/style/minimum-version.t @@ -6,6 +6,7 @@ # which can be found at . # # Written by Russ Allbery +# Copyright 2019 Russ Allbery # Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -29,16 +30,17 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib 't/lib'; -use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); use Test::RRA::Config qw($MINIMUM_VERSION); +use Test::More; + # Skip for normal user installs since this doesn't affect functionality. skip_unless_automated('Minimum version tests'); diff --git a/perl/t/style/strict.t b/perl/t/style/strict.t index a3d2a3e..a87c1fa 100755 --- a/perl/t/style/strict.t +++ b/perl/t/style/strict.t @@ -6,7 +6,7 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2016 Russ Allbery +# Copyright 2016, 2018-2019 Russ Allbery # Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -30,15 +30,16 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib 't/lib'; -use File::Spec; use Test::RRA qw(skip_unless_automated use_prereq); +use File::Spec; + # Skip for normal user installs since this doesn't affect functionality. skip_unless_automated('Strictness tests'); @@ -46,15 +47,40 @@ skip_unless_automated('Strictness tests'); # use 5.012 or later automatically implies use strict. use_prereq('Test::Strict', '0.25'); -# Test everything in the distribution directory except the Build and -# Makefile.PL scripts generated by Module::Build. We also want to check use -# warnings. -$Test::Strict::TEST_SKIP = ['Build', 'Makefile.PL']; +# Directories to exclude from checks. +my %EXCLUDE = map { $_ => 1 } qw(.git blib); + +# Determine whether we want to check the given file or top-level directory. +# Assume that the only interesting files at the top level are directories or +# files ending in *.PL. +# +# $file - Name of the file or directory +# +# Returns: 1 if it should be checked, undef otherwise. +sub should_check { + my ($file) = @_; + return if $EXCLUDE{$file}; + return 1 if -d $file; + return 1 if $file =~ m{ [.] PL \z }xms; + return; +} + +# Test::Strict (as of 0.47) doesn't have a way of excluding whole directories +# from all_perl_files_ok and doesn't exclude .git, which results in false +# positives if there are Perl files unpacked under .git (which is often the +# case when using dgit). We therefore can't just point it at the root of the +# module distribution and instead have to manually construct a list of +# interesting files. +opendir(my $rootdir, File::Spec->curdir) + or die "$0: cannot open current directory: $!\n"; +my @files = File::Spec->no_upwards(readdir($rootdir)); +closedir($rootdir) or die "$0: cannot close current directory: $!\n"; +my @to_check = grep { should_check($_) } @files; + +# Test the files and top-level directories we found, including checking for +# use warnings. $Test::Strict::TEST_WARNINGS = 1; -all_perl_files_ok(File::Spec->curdir); +all_perl_files_ok(@to_check); # Hack to suppress "used only once" warnings. -END { - $Test::Strict::TEST_SKIP = []; - $Test::Strict::TEST_WARNINGS = 0; -} +END { $Test::Strict::TEST_WARNINGS = 0 } diff --git a/perl/t/verifier/ldap-attr.t b/perl/t/verifier/ldap-attr.t index 321822d..4448b38 100755 --- a/perl/t/verifier/ldap-attr.t +++ b/perl/t/verifier/ldap-attr.t @@ -6,7 +6,7 @@ # access to the LDAP server and will be skipped in all other environments. # # Written by Russ Allbery -# Copyright 2018 Russ Allbery +# Copyright 2018, 2020 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -15,12 +15,13 @@ use strict; use warnings; -use Test::More; - use lib 't/lib'; + use Test::RRA qw(skip_unless_author); use Util; +use Test::More; + # This test requires a specific environment setup, so only run it for package # maintainers. skip_unless_author('LDAP verifier tests'); diff --git a/perl/t/verifier/netdb.t b/perl/t/verifier/netdb.t index c9e63d3..2a28468 100755 --- a/perl/t/verifier/netdb.t +++ b/perl/t/verifier/netdb.t @@ -7,7 +7,7 @@ # environments. # # Written by Russ Allbery -# Copyright 2018 Russ Allbery +# Copyright 2018, 2020 Russ Allbery # Copyright 2008, 2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -16,14 +16,15 @@ use strict; use warnings; -use Test::More; - -use Wallet::ACL::NetDB; - use lib 't/lib'; + use Test::RRA qw(skip_unless_author); use Util; +use Test::More; + +use Wallet::ACL::NetDB; + # This test requires a specific environment setup, so only run it for package # maintainers. skip_unless_author('NetDB verifier tests'); diff --git a/portable/asprintf.c b/portable/asprintf.c index aef3639..0451a03 100644 --- a/portable/asprintf.c +++ b/portable/asprintf.c @@ -31,10 +31,10 @@ * with the system versions. */ #if TESTING -# undef asprintf -# undef vasprintf -# define asprintf test_asprintf -# define vasprintf test_vasprintf +# undef asprintf +# undef vasprintf +# define asprintf test_asprintf +# define vasprintf test_vasprintf int test_asprintf(char **, const char *, ...) __attribute__((__format__(printf, 2, 3))); int test_vasprintf(char **, const char *, va_list) diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c index 9de8e65..3632f8b 100644 --- a/portable/krb5-extra.c +++ b/portable/krb5-extra.c @@ -31,17 +31,17 @@ /* Figure out what header files to include for error reporting. */ #if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT) -# if !defined(HAVE_KRB5_GET_ERROR_STRING) -# if defined(HAVE_IBM_SVC_KRB5_SVC_H) -# include -# elif defined(HAVE_ET_COM_ERR_H) -# include -# elif defined(HAVE_KERBEROSV5_COM_ERR_H) -# include -# else -# include -# endif -# endif +# if !defined(HAVE_KRB5_GET_ERROR_STRING) +# if defined(HAVE_IBM_SVC_KRB5_SVC_H) +# include +# elif defined(HAVE_ET_COM_ERR_H) +# include +# elif defined(HAVE_KERBEROSV5_COM_ERR_H) +# include +# else +# include +# endif +# endif #endif /* Used for unused parameters to silence gcc warnings. */ @@ -69,15 +69,15 @@ krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED) { const char *msg; -# if defined(HAVE_KRB5_GET_ERROR_STRING) +# if defined(HAVE_KRB5_GET_ERROR_STRING) msg = krb5_get_error_string(ctx); -# elif defined(HAVE_KRB5_GET_ERR_TEXT) +# elif defined(HAVE_KRB5_GET_ERR_TEXT) msg = krb5_get_err_text(ctx, code); -# elif defined(HAVE_KRB5_SVC_GET_MSG) +# elif defined(HAVE_KRB5_SVC_GET_MSG) krb5_svc_get_msg(code, (char **) &msg); -# else +# else msg = error_message(code); -# endif +# endif if (msg == NULL) return error_unknown; else @@ -100,11 +100,11 @@ krb5_free_error_message(krb5_context ctx UNUSED, const char *msg) { if (msg == error_unknown) return; -# if defined(HAVE_KRB5_GET_ERROR_STRING) +# if defined(HAVE_KRB5_GET_ERROR_STRING) krb5_free_error_string(ctx, (char *) msg); -# elif defined(HAVE_KRB5_SVC_GET_MSG) +# elif defined(HAVE_KRB5_SVC_GET_MSG) krb5_free_string(ctx, (char *) msg); -# endif +# endif } #endif /* !HAVE_KRB5_FREE_ERROR_MESSAGE */ diff --git a/portable/krb5-profile.c b/portable/krb5-profile.c index f4d4652..582e7ac 100644 --- a/portable/krb5-profile.c +++ b/portable/krb5-profile.c @@ -218,7 +218,7 @@ krb5_appdefault_string(krb5_context context, const char *appname, const krb5_dat * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Individual source code files are copyright MIT, Cygnus Support, * OpenVision, Oracle, Sun Soft, FundsXpress, and others. diff --git a/portable/krb5.h b/portable/krb5.h index d8884a7..53092e3 100644 --- a/portable/krb5.h +++ b/portable/krb5.h @@ -20,7 +20,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2015, 2017 Russ Allbery + * Copyright 2015, 2017, 2020 Russ Allbery * Copyright 2010-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -40,16 +40,16 @@ * stripped-down version of config.h with a different name. */ #ifndef CONFIG_H_INCLUDED -# include +# include #endif #include #if defined(HAVE_KRB5_H) -# include +# include #elif defined(HAVE_KERBEROSV5_KRB5_H) -# include +# include #else -# include +# include #endif #include @@ -76,7 +76,12 @@ void krb5_appdefault_string(krb5_context, const char *, const krb5_data *, * Kerberos library. Use krb5_xfree instead. */ #ifndef HAVE_KRB5_FREE_DEFAULT_REALM -# define krb5_free_default_realm(c, r) krb5_xfree(r) +# define krb5_free_default_realm(c, r) krb5_xfree(r) +#endif + +/* Heimdal: krb5_xfree, MIT: krb5_free_unparsed_name. */ +#ifdef HAVE_KRB5_XFREE +# define krb5_free_unparsed_name(c, p) krb5_xfree(p) #endif /* @@ -105,16 +110,17 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context, krb5_get_init_creds_opt **); #endif #ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE -# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS -# define krb5_get_init_creds_opt_free(c, o) krb5_get_init_creds_opt_free(o) -# endif +# ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_FREE_2_ARGS +# define krb5_get_init_creds_opt_free(c, o) \ + krb5_get_init_creds_opt_free(o) +# endif #else -# define krb5_get_init_creds_opt_free(c, o) free(o) +# define krb5_get_init_creds_opt_free(c, o) free(o) #endif /* Heimdal-specific. */ #ifndef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_DEFAULT_FLAGS -# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */ +# define krb5_get_init_creds_opt_set_default_flags(c, p, r, o) /* empty */ #endif /* @@ -123,7 +129,7 @@ krb5_error_code krb5_get_init_creds_opt_alloc(krb5_context, * present in older MIT Kerberos libraries but not prototyped. */ #if !HAVE_DECL_KRB5_KT_FREE_ENTRY -# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e)) +# define krb5_kt_free_entry(c, e) krb5_free_keytab_entry_contents((c), (e)) #endif /* diff --git a/portable/macros.h b/portable/macros.h index 586b07e..5d77fb7 100644 --- a/portable/macros.h +++ b/portable/macros.h @@ -26,9 +26,9 @@ * (to avoid confusion with other macros). */ #ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __attribute__(spec) /* empty */ -# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(spec) /* empty */ +# endif #endif /* @@ -39,10 +39,10 @@ * variadic macro support. */ #if !defined(__attribute__) && !defined(__alloc_size__) -# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \ - && !defined(__clang__) -# define __alloc_size__(spec, args...) /* empty */ -# endif +# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \ + && !defined(__clang__) +# define __alloc_size__(spec, args...) /* empty */ +# endif #endif /* @@ -52,7 +52,7 @@ * compilation context, but there's no push and pop available. */ #if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) -# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wattributes" #endif /* @@ -62,11 +62,11 @@ #undef BEGIN_DECLS #undef END_DECLS #ifdef __cplusplus -# define BEGIN_DECLS extern "C" { -# define END_DECLS } +# define BEGIN_DECLS extern "C" { +# define END_DECLS } #else -# define BEGIN_DECLS /* empty */ -# define END_DECLS /* empty */ +# define BEGIN_DECLS /* empty */ +# define END_DECLS /* empty */ #endif #endif /* !PORTABLE_MACROS_H */ diff --git a/portable/mkstemp.c b/portable/mkstemp.c index 9e3bba1..ebaefc1 100644 --- a/portable/mkstemp.c +++ b/portable/mkstemp.c @@ -25,7 +25,7 @@ #include #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include @@ -35,8 +35,8 @@ * another name. */ #if TESTING -# undef mkstemp -# define mkstemp test_mkstemp +# undef mkstemp +# define mkstemp test_mkstemp int test_mkstemp(char *); #endif diff --git a/portable/reallocarray.c b/portable/reallocarray.c index 3c6ea37..635041e 100644 --- a/portable/reallocarray.c +++ b/portable/reallocarray.c @@ -33,8 +33,8 @@ * it to another name. */ #if TESTING -# undef reallocarray -# define reallocarray test_reallocarray +# undef reallocarray +# define reallocarray test_reallocarray void *test_reallocarray(void *, size_t, size_t); #endif diff --git a/portable/setenv.c b/portable/setenv.c index afa8930..b2cc905 100644 --- a/portable/setenv.c +++ b/portable/setenv.c @@ -28,8 +28,8 @@ * the system version. */ #if TESTING -# undef setenv -# define setenv test_setenv +# undef setenv +# define setenv test_setenv int test_setenv(const char *, const char *, int); #endif diff --git a/portable/snprintf.c b/portable/snprintf.c index a42ef3b..a22e4e4 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -25,6 +25,28 @@ # define vsnprintf test_vsnprintf #endif +/* + * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 + * could you use the __format__ form of the attributes, which is what we use + * (to avoid confusion with other macros). + */ +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(spec) /* empty */ +# endif +#endif + +/* + * Older Clang doesn't support __attribute__((fallthrough)) properly and + * complains about the empty statement that it is decorating. Suppress that + * warning. Also suppress warnings about unknown attributes to handle older + * Clang versions. + */ +#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) +# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wmissing-declarations" +#endif + /* Specific to rra-c-util, but only when debugging is enabled. */ #ifdef DEBUG_SNPRINTF # include @@ -64,7 +86,7 @@ * probably requires libm on most operating systems. Don't yet * support the exponent (e,E) and sigfig (g,G). Also, fmtint() * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code + * which showed it, so that's been fixed. Also, formatted the code * to mutt conventions, and removed dead code left over from the * original. Also, there is now a builtin-test, just compile with: * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm @@ -366,7 +388,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'X': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'x': flags |= DP_F_UNSIGNED; if (cflags == DP_C_SHORT) @@ -388,7 +411,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'E': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); @@ -398,7 +422,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'G': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'g': flags |= DP_F_FP_G; if (cflags == DP_C_LDOUBLE) @@ -714,7 +739,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (intpart != 0) { /* For each digit of INTPART, print one less fractional digit. */ - LLONG temp = intpart; + LLONG temp; for (temp = intpart; temp != 0; temp /= 10) --max; if (max < 0) diff --git a/portable/stdbool.h b/portable/stdbool.h index 3efe4c9..749052a 100644 --- a/portable/stdbool.h +++ b/portable/stdbool.h @@ -28,28 +28,28 @@ * stripped-down version of config.h with a different name. */ #ifndef CONFIG_H_INCLUDED -# include +# include #endif #if HAVE_STDBOOL_H -# include +# include #else -# if HAVE__BOOL -# define bool _Bool -# else -# ifdef __cplusplus +# if HAVE__BOOL +# define bool _Bool +# else +# ifdef __cplusplus typedef bool _Bool; -# elif _WIN32 -# include -# define bool BOOL -# else +# elif _WIN32 +# include +# define bool BOOL +# else typedef unsigned char _Bool; -# define bool _Bool -# endif -# endif -# define false 0 -# define true 1 -# define __bool_true_false_are_defined 1 +# define bool _Bool +# endif +# endif +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 #endif /* @@ -57,7 +57,7 @@ typedef unsigned char _Bool; * fail. Only of interest for programs that also include Perl headers. */ #ifndef HAS_BOOL -# define HAS_BOOL 1 +# define HAS_BOOL 1 #endif #endif /* !PORTABLE_STDBOOL_H */ diff --git a/portable/system.h b/portable/system.h index 6fe4928..3d62b6f 100644 --- a/portable/system.h +++ b/portable/system.h @@ -25,7 +25,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2014, 2016, 2018 Russ Allbery + * Copyright 2014, 2016, 2018, 2020 Russ Allbery * Copyright 2006-2011, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -48,28 +48,28 @@ /* A set of standard ANSI C headers. We don't care about pre-ANSI systems. */ #if HAVE_INTTYPES_H -# include +# include #endif #include #include #include #if HAVE_STDINT_H -# include +# include #endif #include #include #include #if HAVE_STRINGS_H -# include +# include #endif #include #if HAVE_UNISTD_H -# include +# include #endif /* SCO OpenServer gets int32_t from here. */ #if HAVE_SYS_BITYPES_H -# include +# include #endif /* Get the bool type. */ @@ -77,12 +77,12 @@ /* In case uint32_t and associated limits weren't defined. */ #ifndef UINT32_MAX -# define UINT32_MAX 4294967295UL +# define UINT32_MAX 4294967295UL #endif /* Windows provides snprintf under a different name. */ #ifdef _WIN32 -# define snprintf _snprintf +# define snprintf _snprintf #endif /* Windows does not define ssize_t. */ @@ -95,9 +95,9 @@ typedef ptrdiff_t ssize_t; * been defined, all the rest almost certainly have. */ #ifndef STDIN_FILENO -# define STDIN_FILENO 0 -# define STDOUT_FILENO 1 -# define STDERR_FILENO 2 +# define STDIN_FILENO 0 +# define STDOUT_FILENO 1 +# define STDERR_FILENO 2 #endif /* @@ -105,11 +105,11 @@ typedef ptrdiff_t ssize_t; * Autoconf manual, memcpy is a generally portable fallback. */ #ifndef va_copy -# ifdef __va_copy -# define va_copy(d, s) __va_copy((d), (s)) -# else -# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) -# endif +# ifdef __va_copy +# define va_copy(d, s) __va_copy((d), (s)) +# else +# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) +# endif #endif BEGIN_DECLS diff --git a/portable/uio.h b/portable/uio.h index 8635d18..e759d30 100644 --- a/portable/uio.h +++ b/portable/uio.h @@ -27,7 +27,7 @@ /* remctl.h provides its own definition of this struct on Windows. */ #if defined(HAVE_SYS_UIO_H) -# include +# include #elif !defined(REMCTL_H) struct iovec { void *iov_base; diff --git a/tests/data/cppcheck.supp b/tests/data/cppcheck.supp index 5a421df..442c431 100644 --- a/tests/data/cppcheck.supp +++ b/tests/data/cppcheck.supp @@ -4,7 +4,11 @@ // aren't in rra-c-util, for ease of sharing between projects. The ones that // don't apply to a particular project should hopefully be harmless. // -// Copyright 2018 Russ Allbery +// To determine the correct suppression to add for a new error, run cppcheck +// with the --xml flag and then add a suppression for the error id, file +// location, and line. +// +// Copyright 2018-2020 Russ Allbery // // Copying and distribution of this file, with or without modification, are // permitted in any medium without royalty provided the copyright notice and @@ -17,14 +21,35 @@ // every if and loop body with declarations. variableScope +// strlen of a constant string is more maintainable code than hard-coding the +// string length. +constArgument:tests/runtests.c:804 + // False positive due to recursive function. knownConditionTrueFalse:portable/getopt.c:146 // False positive since the string comes from a command-line define. knownConditionTrueFalse:tests/tap/remctl.c:79 +// Stored in the returned ai struct, but cppcheck can't see the assignment +// because of the struct sockaddr * cast. +memleak:portable/getaddrinfo.c:236 + +// Bug in cppcheck 1.89. The address of this variable is passed to a Windows +// function (albeit through a cast). +nullPointer:portable/winsock.c:61 + // Setting the variable to NULL explicitly after deallocation. redundantAssignment:tests/pam-util/options-t.c -// (remctl) Nested assignments in this test confuse cppcheck. -redundantAssignment:tests/server/acl-t.c +// (remctl) Bug in cppcheck 1.89. The address of these variables are passed +// to a PHP function. +uninitvar:php/php_remctl.c:119 +uninitvar:php/php_remctl.c:123 +uninitvar:php/php_remctl.c:315 +uninitvar:php/php5_remctl.c:125 +uninitvar:php/php5_remctl.c:129 +uninitvar:php/php5_remctl.c:321 + +// (pam-krb5) cppcheck doesn't recognize the unused attribute on labels. +unusedLabel:module/auth.c:895 diff --git a/tests/data/fake-kadmin b/tests/data/fake-kadmin index ff90f88..5fbdc27 100755 --- a/tests/data/fake-kadmin +++ b/tests/data/fake-kadmin @@ -6,7 +6,7 @@ # Copyright 2007, 2014 # The Board of Trustees of the Leland Stanford Junior University # -# See LICENSE for licensing terms. +# SPDX-License-Identifier: MIT use strict; use warnings; diff --git a/tests/docs/pod-spelling-t b/tests/docs/pod-spelling-t index 0419c24..04a89e5 100755 --- a/tests/docs/pod-spelling-t +++ b/tests/docs/pod-spelling-t @@ -6,7 +6,7 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2016 Russ Allbery +# Copyright 2016, 2019 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -30,16 +30,17 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use Test::More; use Test::RRA qw(skip_unless_author use_prereq); use Test::RRA::Automake qw(automake_setup perl_dirs); +use Test::More; + # Only run this test for the module author since the required stopwords are # too sensitive to the exact spell-checking program and dictionary. skip_unless_author('Spelling tests'); diff --git a/tests/docs/pod-t b/tests/docs/pod-t index 7ea3409..7b53dda 100755 --- a/tests/docs/pod-t +++ b/tests/docs/pod-t @@ -7,7 +7,7 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2016 Russ Allbery +# Copyright 2016, 2019 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -31,16 +31,17 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); use Test::RRA::Automake qw(automake_setup perl_dirs); +use Test::More; + # Skip this test for normal user installs, since we normally pre-generate all # of the documentation and the end user doesn't care. skip_unless_automated('POD syntax tests'); diff --git a/tests/docs/spdx-license-t b/tests/docs/spdx-license-t index 91072bf..d829080 100755 --- a/tests/docs/spdx-license-t +++ b/tests/docs/spdx-license-t @@ -9,7 +9,7 @@ # The canonical version of this file is maintained in the rra-c-util package, # which can be found at . # -# Copyright 2018 Russ Allbery +# Copyright 2018-2020 Russ Allbery # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -31,17 +31,18 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use File::Basename qw(basename); -use Test::More; use Test::RRA qw(skip_unless_automated); use Test::RRA::Automake qw(all_files automake_setup); +use File::Basename qw(basename); +use Test::More; + # File name (the file without any directory component) and path patterns to # skip for this check. ## no critic (RegularExpressions::ProhibitFixedStringMatches) @@ -68,10 +69,13 @@ my @IGNORE_PATHS = ( qr{ \A php/acinclude [.] m4 \z }xms, # Created by phpize qr{ \A php/build/ }xms, # Created by phpize qr{ \A php/config [.] (guess|sub) \z }xms, # Created by phpize - qr{ \A php/configure [.] in \z }xms, # Created by phpize + qr{ \A php/configure [.] (ac|in) \z }xms, # Created by phpize qr{ \A php/ltmain [.] sh \z }xms, # Created by phpize qr{ \A php/run-tests [.] php \z }xms, # Created by phpize + qr{ \A python/ .* [.] egg-info/ }xms, # Python build files + qr{ \A tests/config/ (?!README) }xms, # Test configuration qr{ [.] l?a \z }xms, # Created by libtool + qr{ [.] o \z }xms, # Compiler objects ); ## use critic @@ -91,9 +95,7 @@ sub check_file { my ($path) = @_; my $filename = basename($path); - # Ignore files in the whitelist, binary files, and files under 1KB. The - # latter can be rolled up into the overall project license and the license - # notice may be a substantial portion of the file size. + # Ignore files in the whitelist and binary files. for my $pattern (@IGNORE) { return if $filename =~ $pattern; } @@ -101,16 +103,18 @@ sub check_file { return if $path =~ $pattern; } return if !-T $path; - return if -s $path < 1024; # Scan the file. - my ($saw_spdx, $skip_spdx); + my ($saw_legacy_notice, $saw_spdx, $skip_spdx); open(my $file, '<', $path) or BAIL_OUT("Cannot open $path: $!"); while (defined(my $line = <$file>)) { if ($line =~ m{ Generated [ ] by [ ] libtool [ ] }xms) { close($file) or BAIL_OUT("Cannot close $path: $!"); return; } + if ($line =~ m{ \b See \s+ LICENSE \s+ for \s+ licensing }xms) { + $saw_legacy_notice = 1; + } if ($line =~ m{ \b SPDX-License-Identifier: \s+ \S+ }xms) { $saw_spdx = 1; last; @@ -121,7 +125,16 @@ sub check_file { } } close($file) or BAIL_OUT("Cannot close $path: $!"); - ok($saw_spdx || $skip_spdx, $path); + + # If there is a legacy license notice, report a failure regardless of file + # size. Otherwise, skip files under 1KB. They can be rolled up into the + # overall project license and the license notice may be a substantial + # portion of the file size. + if ($saw_legacy_notice) { + ok(!$saw_legacy_notice, "$path has legacy license notice"); + } else { + ok($saw_spdx || $skip_spdx || -s $path < 1024, $path); + } return; } diff --git a/tests/perl/minimum-version-t b/tests/perl/minimum-version-t index 7d81b46..420ce36 100755 --- a/tests/perl/minimum-version-t +++ b/tests/perl/minimum-version-t @@ -10,7 +10,7 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2016 Russ Allbery +# Copyright 2016, 2019-2020 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -34,17 +34,18 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); use Test::RRA::Automake qw(automake_setup perl_dirs); use Test::RRA::Config qw($MINIMUM_VERSION %MINIMUM_VERSION); +use Test::More; + # Skip for normal user installs since this doesn't affect functionality. skip_unless_automated('Minimum version tests'); @@ -55,7 +56,7 @@ use_prereq('Test::MinimumVersion'); automake_setup(); # For each exception case in %MINIMUM_VERSION, check the files that should -# have that minium version. Sort for reproducible test order. Also +# have that minimum version. Sort for reproducible test order. Also # accumulate the list of directories we've already tested. my @tested; for my $version (sort keys %MINIMUM_VERSION) { diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t index 878cc2d..31ee988 100755 --- a/tests/perl/module-version-t +++ b/tests/perl/module-version-t @@ -12,7 +12,7 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; @@ -27,11 +27,13 @@ BEGIN { } } -use Getopt::Long qw(GetOptions); use Test::RRA qw(skip_unless_automated); use Test::RRA::Automake qw(automake_setup); use Test::RRA::ModuleVersion qw(test_module_versions update_module_versions); +use Cwd qw(getcwd); +use Getopt::Long qw(GetOptions); + # Return the current version and, optionally, the package name from the NEWS # file. Munges the version to be appropriate for Perl if necessary. # @@ -85,9 +87,9 @@ if (!$update) { # Get the package name and version. my ($version, $package) = news_version(); -# rra-c-util itself checks the versions of the testing support modules instead -# of an embedded tree of Perl modules. -my $root = ($package eq 'rra-c-util') ? 'tests/tap/perl' : 'perl/lib'; +# rra-c-util, but only it, also checks the versions of all the testing support +# modules. +my $root = ($package eq 'rra-c-util') ? getcwd() : 'perl/lib'; # Main routine. We run as either a test suite or as a script to update all of # the module versions, selecting based on whether we got the -u / --update @@ -114,7 +116,7 @@ B [B<--update>] =head1 REQUIREMENTS -Perl 5.6.2 or later. +Perl 5.8 or later. =head1 DESCRIPTION @@ -155,7 +157,7 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2014, 2016 Russ Allbery +Copyright 2014, 2016, 2019-2020 Russ Allbery Copyright 2013 The Board of Trustees of the Leland Stanford Junior University diff --git a/tests/perl/strict-t b/tests/perl/strict-t index 09ce157..6eae216 100755 --- a/tests/perl/strict-t +++ b/tests/perl/strict-t @@ -10,7 +10,7 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2016 Russ Allbery +# Copyright 2016, 2019 Russ Allbery # Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -34,17 +34,18 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); use Test::RRA::Automake qw(automake_setup perl_dirs); use Test::RRA::Config qw(@STRICT_IGNORE @STRICT_PREREQ); +use Test::More; + # Skip for normal user installs since this doesn't affect functionality. skip_unless_automated('Strictness tests'); diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c index 7e8a68f..d14712f 100644 --- a/tests/portable/snprintf-t.c +++ b/tests/portable/snprintf-t.c @@ -5,7 +5,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2000-2006, 2018 Russ Allbery + * Copyright 2000-2006, 2018-2020 Russ Allbery * Copyright 2009-2010 * The Board of Trustees of the Leland Stanford Junior University * Copyright 1995 Patrick Powell @@ -28,7 +28,7 @@ * formats for easy testing. */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || defined(__clang__) -# pragma GCC diagnostic ignored "-Wformat-nonliteral" +# pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif /* @@ -40,20 +40,12 @@ int test_vsnprintf(char *str, size_t count, const char *fmt, va_list args); static const char string[] = "abcdefghijklmnopqrstuvwxyz0123456789"; +/* clang-format off */ + static const char *const fp_formats[] = { - "%-1.5f", "%1.5f", "%31.9f", "%10.5f", "% 10.5f", "%+22.9f", - "%+4.9f", "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f", + "%-1.5f", "%1.5f", "%31.6f", "%10.5f", "% 10.5f", "%+22.6f", + "%+4.6f", "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f", "%f", - - /* %e and %g formats aren't really implemented yet. */ -#if 0 - "%-1.5e", "%1.5e", "%31.9e", "%10.5e", "% 10.5e", "%+22.9e", - "%+4.9e", "%01.3e", "%3.1e", "%3.2e", "%.0e", "%.1e", - "%e", - "%-1.5g", "%1.5g", "%31.9g", "%10.5g", "% 10.5g", "%+22.9g", - "%+4.9g", "%01.3g", "%3.1g", "%3.2g", "%.0g", "%.1g", - "%g", -#endif NULL }; static const char *const int_formats[] = { @@ -99,10 +91,12 @@ static unsigned long long ullong_nums[] = { 0 }; +/* clang-format on */ + static void -test_format(bool trunc, const char *expected, int count, - const char *format, ...) +test_format(bool trunc, const char *expected, int count, const char *format, + ...) { char buf[128]; int result; @@ -124,12 +118,13 @@ main(void) long lcount; char lgbuf[128]; - plan(8 + - (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums) - + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums) - + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums) - + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums) - + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums)) * 2); + plan(8 + + (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums) + + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums) + + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums) + + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums) + + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums)) + * 2); is_int(4, test_snprintf(NULL, 0, "%s", "abcd"), "simple string length"); is_int(2, test_snprintf(NULL, 0, "%d", 20), "number length"); @@ -156,8 +151,8 @@ main(void) string, -2.5); test_format(true, "abcdefghij4444", 14, "%.10s%n%d", string, &count, 4444); is_int(10, count, "correct output from %%n"); - test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln", - &count, string, &lcount); + test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln", &count, + string, &lcount); is_int(0, count, "correct output from two %%n"); is_int(31, lcount, "correct output from long %%ln"); test_format(true, "(null)", 6, "%s", (char *) NULL); diff --git a/tests/runtests.c b/tests/runtests.c index af15a5c..1050120 100644 --- a/tests/runtests.c +++ b/tests/runtests.c @@ -8,7 +8,7 @@ * should be sent to the e-mail address below. This program is part of C TAP * Harness . * - * Copyright 2000-2001, 2004, 2006-2018 Russ Allbery + * Copyright 2000-2001, 2004, 2006-2019 Russ Allbery * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -93,9 +93,9 @@ /* Required for fdopen(), getopt(), and putenv(). */ #if defined(__STRICT_ANSI__) || defined(PEDANTIC) -# ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 -# endif +# ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 +# endif #endif #include @@ -120,7 +120,7 @@ /* AIX 6.1 (and possibly later) doesn't have WCOREDUMP. */ #ifndef WCOREDUMP -# define WCOREDUMP(status) ((unsigned)(status) & 0x80) +# define WCOREDUMP(status) ((unsigned) (status) &0x80) #endif /* @@ -129,9 +129,9 @@ * have. */ #ifndef STDIN_FILENO -# define STDIN_FILENO 0 -# define STDOUT_FILENO 1 -# define STDERR_FILENO 2 +# define STDIN_FILENO 0 +# define STDOUT_FILENO 1 +# define STDERR_FILENO 2 #endif /* @@ -149,58 +149,50 @@ * $(abs_top_builddir) respectively. */ #ifndef C_TAP_SOURCE -# define C_TAP_SOURCE NULL +# define C_TAP_SOURCE NULL #endif #ifndef C_TAP_BUILD -# define C_TAP_BUILD NULL +# define C_TAP_BUILD NULL #endif /* Test status codes. */ -enum test_status { - TEST_FAIL, - TEST_PASS, - TEST_SKIP, - TEST_INVALID -}; +enum test_status { TEST_FAIL, TEST_PASS, TEST_SKIP, TEST_INVALID }; /* Really, just a boolean, but this is more self-documenting. */ -enum test_verbose { - CONCISE = 0, - VERBOSE = 1 -}; +enum test_verbose { CONCISE = 0, VERBOSE = 1 }; /* Indicates the state of our plan. */ enum plan_status { - PLAN_INIT, /* Nothing seen yet. */ - PLAN_FIRST, /* Plan seen before any tests. */ - PLAN_PENDING, /* Test seen and no plan yet. */ - PLAN_FINAL /* Plan seen after some tests. */ + PLAN_INIT, /* Nothing seen yet. */ + PLAN_FIRST, /* Plan seen before any tests. */ + PLAN_PENDING, /* Test seen and no plan yet. */ + PLAN_FINAL /* Plan seen after some tests. */ }; /* Error exit statuses for test processes. */ -#define CHILDERR_DUP 100 /* Couldn't redirect stderr or stdout. */ -#define CHILDERR_EXEC 101 /* Couldn't exec child process. */ -#define CHILDERR_STDIN 102 /* Couldn't open stdin file. */ -#define CHILDERR_STDERR 103 /* Couldn't open stderr file. */ +#define CHILDERR_DUP 100 /* Couldn't redirect stderr or stdout. */ +#define CHILDERR_EXEC 101 /* Couldn't exec child process. */ +#define CHILDERR_STDIN 102 /* Couldn't open stdin file. */ +#define CHILDERR_STDERR 103 /* Couldn't open stderr file. */ /* Structure to hold data for a set of tests. */ struct testset { - char *file; /* The file name of the test. */ - char **command; /* The argv vector to run the command. */ - enum plan_status plan; /* The status of our plan. */ - unsigned long count; /* Expected count of tests. */ - unsigned long current; /* The last seen test number. */ - unsigned int length; /* The length of the last status message. */ - unsigned long passed; /* Count of passing tests. */ - unsigned long failed; /* Count of failing lists. */ - unsigned long skipped; /* Count of skipped tests (passed). */ - unsigned long allocated; /* The size of the results table. */ - enum test_status *results; /* Table of results by test number. */ - unsigned int aborted; /* Whether the set was aborted. */ - unsigned int reported; /* Whether the results were reported. */ - int status; /* The exit status of the test. */ - unsigned int all_skipped; /* Whether all tests were skipped. */ - char *reason; /* Why all tests were skipped. */ + char *file; /* The file name of the test. */ + char **command; /* The argv vector to run the command. */ + enum plan_status plan; /* The status of our plan. */ + unsigned long count; /* Expected count of tests. */ + unsigned long current; /* The last seen test number. */ + unsigned int length; /* The length of the last status message. */ + unsigned long passed; /* Count of passing tests. */ + unsigned long failed; /* Count of failing lists. */ + unsigned long skipped; /* Count of skipped tests (passed). */ + unsigned long allocated; /* The size of the results table. */ + enum test_status *results; /* Table of results by test number. */ + unsigned int aborted; /* Whether the set was aborted. */ + unsigned int reported; /* Whether the results were reported. */ + int status; /* The exit status of the test. */ + unsigned int all_skipped; /* Whether all tests were skipped. */ + char *reason; /* Why all tests were skipped. */ }; /* Structure to hold a linked list of test sets. */ @@ -246,12 +238,13 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ -------------------------- -------------- ---- ---- ------------------------"; /* Include the file name and line number in malloc failures. */ -#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__) -#define xmalloc(size) x_malloc((size), __FILE__, __LINE__) -#define xstrdup(p) x_strdup((p), __FILE__, __LINE__) -#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__) -#define xreallocarray(p, n, size) \ - x_reallocarray((p), (n), (size), __FILE__, __LINE__) +#define xcalloc(n, type) \ + ((type *) x_calloc((n), sizeof(type), __FILE__, __LINE__)) +#define xmalloc(size) ((char *) x_malloc((size), __FILE__, __LINE__)) +#define xstrdup(p) x_strdup((p), __FILE__, __LINE__) +#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__) +#define xreallocarray(p, n, type) \ + ((type *) x_reallocarray((p), (n), sizeof(type), __FILE__, __LINE__)) /* * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 @@ -259,9 +252,9 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * (to avoid confusion with other macros). */ #ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __attribute__(spec) /* empty */ -# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(spec) /* empty */ +# endif #endif /* @@ -272,11 +265,11 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * variadic macro support. */ #if !defined(__attribute__) && !defined(__alloc_size__) -# if defined(__GNUC__) && !defined(__clang__) -# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) -# define __alloc_size__(spec, args...) /* empty */ -# endif -# endif +# if defined(__GNUC__) && !defined(__clang__) +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) +# define __alloc_size__(spec, args...) /* empty */ +# endif +# endif #endif /* @@ -286,7 +279,7 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ * compilation context, but there's no push and pop available. */ #if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) -# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wattributes" #endif /* Declare internal functions that benefit from compiler attributes. */ @@ -394,6 +387,9 @@ x_malloc(size_t size, const char *file, int line) static void * x_reallocarray(void *p, size_t n, size_t size, const char *file, int line) { + n = (n > 0) ? n : 1; + size = (size > 0) ? size : 1; + if (n > 0 && UINT_MAX / n <= size) sysdie("realloc too large at %s line %d", file, line); p = realloc(p, n * size); @@ -414,10 +410,10 @@ x_strdup(const char *s, const char *file, int line) size_t len; len = strlen(s) + 1; - p = malloc(len); + p = (char *) malloc(len); if (p == NULL) - sysdie("failed to strdup %lu bytes at %s line %d", - (unsigned long) len, file, line); + sysdie("failed to strdup %lu bytes at %s line %d", (unsigned long) len, + file, line); memcpy(p, s, len); return p; } @@ -439,10 +435,10 @@ x_strndup(const char *s, size_t size, const char *file, int line) char *copy; /* Don't assume that the source string is nul-terminated. */ - for (p = s; (size_t) (p - s) < size && *p != '\0'; p++) + for (p = s; (size_t)(p - s) < size && *p != '\0'; p++) ; - len = (size_t) (p - s); - copy = malloc(len + 1); + len = (size_t)(p - s); + copy = (char *) malloc(len + 1); if (copy == NULL) sysdie("failed to strndup %lu bytes at %s line %d", (unsigned long) len, file, line); @@ -539,7 +535,7 @@ tv_sum(const struct timeval *tv1, const struct timeval *tv2) static const char * skip_whitespace(const char *p) { - while (isspace((unsigned char)(*p))) + while (isspace((unsigned char) (*p))) p++; return p; } @@ -552,7 +548,7 @@ skip_whitespace(const char *p) static const char * skip_non_whitespace(const char *p) { - while (*p != '\0' && !isspace((unsigned char)(*p))) + while (*p != '\0' && !isspace((unsigned char) (*p))) p++; return p; } @@ -670,10 +666,10 @@ resize_results(struct testset *ts, unsigned long n) */ if (ts->allocated == 0) { s = (n > 32) ? n : 32; - ts->results = xcalloc(s, sizeof(enum test_status)); + ts->results = xcalloc(s, enum test_status); } else { s = (n > ts->allocated + 1024) ? n : ts->allocated + 1024; - ts->results = xreallocarray(ts->results, s, sizeof(enum test_status)); + ts->results = xreallocarray(ts->results, s, enum test_status); } /* Set the results for the newly-allocated test array. */ @@ -787,8 +783,7 @@ test_plan(const char *line, struct testset *ts, enum test_verbose verbose) * reported status. */ static void -test_checkline(const char *line, struct testset *ts, - enum test_verbose verbose) +test_checkline(const char *line, struct testset *ts, enum test_verbose verbose) { enum test_status status = TEST_PASS; const char *bail; @@ -828,7 +823,7 @@ test_checkline(const char *line, struct testset *ts, return; /* If we haven't yet seen a plan, look for one. */ - if (ts->plan == PLAN_INIT && isdigit((unsigned char)(*line))) { + if (ts->plan == PLAN_INIT && isdigit((unsigned char) (*line))) { if (!test_plan(line, ts, verbose)) return; } else if (strncmp(line, "1..", 3) == 0) { @@ -879,7 +874,7 @@ test_checkline(const char *line, struct testset *ts, * Handle directives. We should probably do something more interesting * with unexpected passes of todo tests. */ - while (isdigit((unsigned char)(*line))) + while (isdigit((unsigned char) (*line))) line++; line = skip_whitespace(line); if (*line == '#') { @@ -902,10 +897,17 @@ test_checkline(const char *line, struct testset *ts, /* Good results. Increment our various counters. */ switch (status) { - case TEST_PASS: ts->passed++; break; - case TEST_FAIL: ts->failed++; break; - case TEST_SKIP: ts->skipped++; break; - case TEST_INVALID: break; + case TEST_PASS: + ts->passed++; + break; + case TEST_FAIL: + ts->failed++; + break; + case TEST_SKIP: + ts->skipped++; + break; + case TEST_INVALID: + break; } ts->current = current; ts->results[current - 1] = status; @@ -1252,7 +1254,7 @@ find_test(const char *name, const char *source, const char *build) char *path = NULL; const char *bases[3], *suffix, *base; unsigned int i, j; - const char *suffixes[3] = { "-t", ".t", "" }; + const char *suffixes[3] = {"-t", ".t", ""}; /* Possible base directories. */ bases[0] = "."; @@ -1321,11 +1323,9 @@ parse_test_list_line(const char *line, struct testset *ts, const char *source, end = skip_non_whitespace(p); if (strncmp(p, "libtool", end - p) == 0) { use_libtool = 1; - p = end; } else if (strncmp(p, "valgrind", end - p) == 0) { valgrind = getenv("C_TAP_VALGRIND"); use_valgrind = (valgrind != NULL); - p = end; } else { option = xstrndup(p, end - p); die("unknown test list option %s", option); @@ -1346,7 +1346,7 @@ parse_test_list_line(const char *line, struct testset *ts, const char *source, } /* Now, build the command. */ - ts->command = xcalloc(len + 1, sizeof(char *)); + ts->command = xcalloc(len + 1, char *); i = 0; if (use_valgrind && valgrind != NULL) { if (use_libtool) { @@ -1388,7 +1388,7 @@ read_test_list(const char *filename, const char *source, const char *build) struct testlist *listhead, *current; /* Create the initial container list that will hold our results. */ - listhead = xcalloc(1, sizeof(struct testlist)); + listhead = xcalloc(1, struct testlist); current = NULL; /* @@ -1419,10 +1419,10 @@ read_test_list(const char *filename, const char *source, const char *build) if (current == NULL) current = listhead; else { - current->next = xcalloc(1, sizeof(struct testlist)); + current->next = xcalloc(1, struct testlist); current = current->next; } - current->ts = xcalloc(1, sizeof(struct testset)); + current->ts = xcalloc(1, struct testset); current->ts->plan = PLAN_INIT; /* Parse the line and store the results in the testset struct. */ @@ -1454,7 +1454,7 @@ build_test_list(char *argv[], int argc, const char *source, const char *build) struct testlist *listhead, *current; /* Create the initial container list that will hold our results. */ - listhead = xcalloc(1, sizeof(struct testlist)); + listhead = xcalloc(1, struct testlist); current = NULL; /* Walk the list of arguments and create test sets for them. */ @@ -1462,13 +1462,13 @@ build_test_list(char *argv[], int argc, const char *source, const char *build) if (current == NULL) current = listhead; else { - current->next = xcalloc(1, sizeof(struct testlist)); + current->next = xcalloc(1, struct testlist); current = current->next; } - current->ts = xcalloc(1, sizeof(struct testset)); + current->ts = xcalloc(1, struct testset); current->ts->plan = PLAN_INIT; current->ts->file = xstrdup(argv[i]); - current->ts->command = xcalloc(2, sizeof(char *)); + current->ts->command = xcalloc(2, char *); current->ts->command[0] = find_test(current->ts->file, source, build); current->ts->command[1] = NULL; } @@ -1575,10 +1575,10 @@ test_batch(struct testlist *tests, enum test_verbose verbose) /* If the test fails, we shuffle it over to the fail list. */ if (!succeeded) { if (failhead == NULL) { - failhead = xmalloc(sizeof(struct testset)); + failhead = xcalloc(1, struct testlist); failtail = failhead; } else { - failtail->next = xmalloc(sizeof(struct testset)); + failtail->next = xcalloc(1, struct testlist); failtail = failtail->next; } failtail->ts = ts; @@ -1617,8 +1617,7 @@ test_batch(struct testlist *tests, enum test_verbose verbose) else printf("Aborted %lu test sets", aborted); printf(", passed %lu/%lu tests", passed, total); - } - else if (failed == 0) + } else if (failed == 0) fputs("All tests successful", stdout); else printf("Failed %lu/%lu tests, %.2f%% okay", failed, total, @@ -1632,8 +1631,8 @@ test_batch(struct testlist *tests, enum test_verbose verbose) puts("."); printf("Files=%u, Tests=%lu", count, total); printf(", %.2f seconds", tv_diff(&end, &start)); - printf(" (%.2f usr + %.2f sys = %.2f CPU)\n", - tv_seconds(&stats.ru_utime), tv_seconds(&stats.ru_stime), + printf(" (%.2f usr + %.2f sys = %.2f CPU)\n", tv_seconds(&stats.ru_utime), + tv_seconds(&stats.ru_stime), tv_sum(&stats.ru_utime, &stats.ru_stime)); return (failed == 0 && aborted == 0); } diff --git a/tests/style/obsolete-strings-t b/tests/style/obsolete-strings-t index b3d8fd4..02fd30c 100755 --- a/tests/style/obsolete-strings-t +++ b/tests/style/obsolete-strings-t @@ -9,7 +9,7 @@ # The canonical version of this file is maintained in the rra-c-util package, # which can be found at . # -# Copyright 2016, 2018 Russ Allbery +# Copyright 2016, 2018-2019 Russ Allbery # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -31,17 +31,18 @@ # # SPDX-License-Identifier: MIT -use 5.006; +use 5.008; use strict; use warnings; use lib "$ENV{C_TAP_SOURCE}/tap/perl"; -use File::Basename qw(basename); -use Test::More; use Test::RRA qw(skip_unless_author); use Test::RRA::Automake qw(all_files automake_setup); +use File::Basename qw(basename); +use Test::More; + # Bad patterns to search for. my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms); my @BAD_STRINGS = qw(rra@stanford.edu RRA_MAINTAINER_TESTS); diff --git a/tests/tap/basic.c b/tests/tap/basic.c index 8624839..b5f42d0 100644 --- a/tests/tap/basic.c +++ b/tests/tap/basic.c @@ -13,7 +13,7 @@ * documentation is at . * * Written by Russ Allbery - * Copyright 2009-2018 Russ Allbery + * Copyright 2009-2019 Russ Allbery * Copyright 2001-2002, 2004-2008, 2011-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -45,9 +45,9 @@ #include #include #ifdef _WIN32 -# include +# include #else -# include +# include #endif #include #include @@ -56,8 +56,8 @@ /* Windows provides mkdir and rmdir under different names. */ #ifdef _WIN32 -# define mkdir(p, m) _mkdir(p) -# define rmdir(p) _rmdir(p) +# define mkdir(p, m) _mkdir(p) +# define rmdir(p) _rmdir(p) #endif /* @@ -72,7 +72,7 @@ unsigned long testnum = 1; * We can get the highest test count from testnum. */ static unsigned long _planned = 0; -static unsigned long _failed = 0; +static unsigned long _failed = 0; /* * Store the PID of the process that called plan() and only summarize @@ -101,6 +101,8 @@ static int _aborted = 0; */ struct cleanup_func { test_cleanup_func func; + test_cleanup_func_with_data func_with_data; + void *data; struct cleanup_func *next; }; static struct cleanup_func *cleanup_funcs = NULL; @@ -126,15 +128,15 @@ static struct diag_file *diag_files = NULL; * print_desc, which has to be done in a macro. Assumes that format is the * argument immediately before the variadic arguments. */ -#define PRINT_DESC(prefix, format) \ - do { \ - if (format != NULL) { \ - va_list args; \ - printf("%s", prefix); \ - va_start(args, format); \ - vprintf(format, args); \ - va_end(args); \ - } \ +#define PRINT_DESC(prefix, format) \ + do { \ + if (format != NULL) { \ + va_list args; \ + printf("%s", prefix); \ + va_start(args, format); \ + vprintf(format, args); \ + va_end(args); \ + } \ } while (0) @@ -171,7 +173,7 @@ concat(const char *first, ...) length++; /* Create the string. */ - result = bmalloc(length); + result = bcalloc_type(length, char); va_start(args, first); offset = 0; for (string = first; string != NULL; string = va_arg(args, const char *)) { @@ -184,6 +186,68 @@ concat(const char *first, ...) } +/* + * Helper function for check_diag_files to handle a single line in a diag + * file. + * + * The general scheme here used is as follows: read one line of output. If we + * get NULL, check for an error. If there was one, bail out of the test + * program; otherwise, return, and the enclosing loop will check for EOF. + * + * If we get some data, see if it ends in a newline. If it doesn't end in a + * newline, we have one of two cases: our buffer isn't large enough, in which + * case we resize it and try again, or we have incomplete data in the file, in + * which case we rewind the file and will try again next time. + * + * Returns a boolean indicating whether the last line was incomplete. + */ +static int +handle_diag_file_line(struct diag_file *file, fpos_t where) +{ + int size; + size_t length; + + /* Read the next line from the file. */ + size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize; + if (fgets(file->buffer, size, file->file) == NULL) { + if (ferror(file->file)) + sysbail("cannot read from %s", file->name); + return 0; + } + + /* + * See if the line ends in a newline. If not, see which error case we + * have. + */ + length = strlen(file->buffer); + if (file->buffer[length - 1] != '\n') { + int incomplete = 0; + + /* Check whether we ran out of buffer space and resize if so. */ + if (length < file->bufsize - 1) + incomplete = 1; + else { + file->bufsize += BUFSIZ; + file->buffer = + breallocarray_type(file->buffer, file->bufsize, char); + } + + /* + * On either incomplete lines or too small of a buffer, rewind + * and read the file again (on the next pass, if incomplete). + * It's simpler than trying to double-buffer the file. + */ + if (fsetpos(file->file, &where) < 0) + sysbail("cannot set position in %s", file->name); + return incomplete; + } + + /* We saw a complete line. Print it out. */ + printf("# %s", file->buffer); + return 0; +} + + /* * Check all registered diag_files for any output. We only print out the * output if we see a complete line; otherwise, we wait for the next newline. @@ -193,20 +257,10 @@ check_diag_files(void) { struct diag_file *file; fpos_t where; - size_t length; - int size, incomplete; + int incomplete; /* - * Walk through each file and read each line of output available. The - * general scheme here used is as follows: try to read a line of output at - * a time. If we get NULL, check for EOF; on EOF, advance to the next - * file. - * - * If we get some data, see if it ends in a newline. If it doesn't end in - * a newline, we have one of two cases: our buffer isn't large enough, in - * which case we resize it and try again, or we have incomplete data in - * the file, in which case we rewind the file and will try again next - * time. + * Walk through each file and read each line of output available. */ for (file = diag_files; file != NULL; file = file->next) { clearerr(file->file); @@ -218,41 +272,7 @@ check_diag_files(void) /* Continue until we get EOF or an incomplete line of data. */ incomplete = 0; while (!feof(file->file) && !incomplete) { - size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize; - if (fgets(file->buffer, size, file->file) == NULL) { - if (ferror(file->file)) - sysbail("cannot read from %s", file->name); - continue; - } - - /* - * See if the line ends in a newline. If not, see which error - * case we have. Use UINT_MAX as a substitute for SIZE_MAX (see - * the comment for breallocarray). - */ - length = strlen(file->buffer); - if (file->buffer[length - 1] != '\n') { - if (length < file->bufsize - 1) - incomplete = 1; - else { - if (file->bufsize >= UINT_MAX - BUFSIZ) - sysbail("line too long in %s", file->name); - file->bufsize += BUFSIZ; - file->buffer = brealloc(file->buffer, file->bufsize); - } - - /* - * On either incomplete lines or too small of a buffer, rewind - * and read the file again (on the next pass, if incomplete). - * It's simpler than trying to double-buffer the file. - */ - if (fsetpos(file->file, &where) < 0) - sysbail("cannot set position in %s", file->name); - continue; - } - - /* We saw a complete line. Print it out. */ - printf("# %s", file->buffer); + incomplete = handle_diag_file_line(file, where); } } } @@ -305,7 +325,13 @@ finish(void) */ primary = (_process == 0 || getpid() == _process); while (cleanup_funcs != NULL) { - cleanup_funcs->func(success, primary); + if (cleanup_funcs->func_with_data) { + void *data = cleanup_funcs->data; + + cleanup_funcs->func_with_data(success, primary, data); + } else { + cleanup_funcs->func(success, primary); + } current = cleanup_funcs; cleanup_funcs = cleanup_funcs->next; free(current); @@ -503,7 +529,7 @@ is_bool(int left, int right, const char *format, ...) if (success) printf("ok %lu", testnum++); else { - diag(" left: %s", !!left ? "true" : "false"); + diag(" left: %s", !!left ? "true" : "false"); diag("right: %s", !!right ? "true" : "false"); printf("not ok %lu", testnum++); _failed++; @@ -563,7 +589,7 @@ is_string(const char *left, const char *right, const char *format, ...) if (success) printf("ok %lu", testnum++); else { - diag(" left: %s", left == NULL ? "(null)" : left); + diag(" left: %s", left == NULL ? "(null)" : left); diag("right: %s", right == NULL ? "(null)" : right); printf("not ok %lu", testnum++); _failed++; @@ -617,8 +643,8 @@ is_blob(const void *left, const void *right, size_t len, const char *format, if (success) printf("ok %lu", testnum++); else { - const unsigned char *left_c = left; - const unsigned char *right_c = right; + const unsigned char *left_c = (const unsigned char *) left; + const unsigned char *right_c = (const unsigned char *) right; for (i = 0; i < len; i++) { if (left_c[i] != right_c[i]) @@ -728,12 +754,12 @@ diag_file_add(const char *name) { struct diag_file *file, *prev; - file = bcalloc(1, sizeof(struct diag_file)); + file = bcalloc_type(1, struct diag_file); file->name = bstrdup(name); file->file = fopen(file->name, "r"); if (file->file == NULL) sysbail("cannot open %s", name); - file->buffer = bmalloc(BUFSIZ); + file->buffer = bcalloc_type(BUFSIZ, char); file->bufsize = BUFSIZ; if (diag_files == NULL) diag_files = file; @@ -781,7 +807,7 @@ bcalloc(size_t n, size_t size) p = calloc(n, size); if (p == NULL) - sysbail("failed to calloc %lu", (unsigned long)(n * size)); + sysbail("failed to calloc %lu", (unsigned long) (n * size)); return p; } @@ -852,7 +878,7 @@ bstrdup(const char *s) size_t len; len = strlen(s) + 1; - p = malloc(len); + p = (char *) malloc(len); if (p == NULL) sysbail("failed to strdup %lu bytes", (unsigned long) len); memcpy(p, s, len); @@ -873,11 +899,11 @@ bstrndup(const char *s, size_t n) size_t length; /* Don't assume that the source string is nul-terminated. */ - for (p = s; (size_t) (p - s) < n && *p != '\0'; p++) + for (p = s; (size_t)(p - s) < n && *p != '\0'; p++) ; - length = (size_t) (p - s); - copy = malloc(length + 1); - if (p == NULL) + length = (size_t)(p - s); + copy = (char *) malloc(length + 1); + if (copy == NULL) sysbail("failed to strndup %lu bytes", (unsigned long) length); memcpy(copy, s, length); copy[length] = '\0'; @@ -896,7 +922,7 @@ test_file_path(const char *file) { char *base; char *path = NULL; - const char *envs[] = { "C_TAP_BUILD", "C_TAP_SOURCE", NULL }; + const char *envs[] = {"C_TAP_BUILD", "C_TAP_SOURCE", NULL}; int i; for (i = 0; envs[i] != NULL; i++) { @@ -965,21 +991,39 @@ test_tmpdir_free(char *path) free(path); } - -/* - * Register a cleanup function that is called when testing ends. All such - * registered functions will be run by finish. - */ -void -test_cleanup_register(test_cleanup_func func) +static void +register_cleanup(test_cleanup_func func, + test_cleanup_func_with_data func_with_data, void *data) { struct cleanup_func *cleanup, **last; - cleanup = bmalloc(sizeof(struct cleanup_func)); + cleanup = bcalloc_type(1, struct cleanup_func); cleanup->func = func; + cleanup->func_with_data = func_with_data; + cleanup->data = data; cleanup->next = NULL; last = &cleanup_funcs; while (*last != NULL) last = &(*last)->next; *last = cleanup; } + +/* + * Register a cleanup function that is called when testing ends. All such + * registered functions will be run by finish. + */ +void +test_cleanup_register(test_cleanup_func func) +{ + register_cleanup(func, NULL, NULL); +} + +/* + * Same as above, but also allows an opaque pointer to be passed to the cleanup + * function. + */ +void +test_cleanup_register_with_data(test_cleanup_func_with_data func, void *data) +{ + register_cleanup(NULL, func, data); +} diff --git a/tests/tap/basic.h b/tests/tap/basic.h index 3f46e4f..45f15f2 100644 --- a/tests/tap/basic.h +++ b/tests/tap/basic.h @@ -5,7 +5,7 @@ * documentation is at . * * Written by Russ Allbery - * Copyright 2009-2018 Russ Allbery + * Copyright 2009-2019 Russ Allbery * Copyright 2001-2002, 2004-2008, 2011-2012, 2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -33,9 +33,9 @@ #ifndef TAP_BASIC_H #define TAP_BASIC_H 1 +#include /* va_list */ +#include /* size_t */ #include -#include /* va_list */ -#include /* size_t */ /* * Used for iterating through arrays. ARRAY_SIZE returns the number of @@ -43,8 +43,8 @@ * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it * legal to refer to such a pointer as long as it's never dereferenced). */ -#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) -#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)]) +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) +#define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)]) BEGIN_DECLS @@ -77,8 +77,7 @@ int ok(int success, const char *format, ...) __attribute__((__format__(printf, 2, 3))); int okv(int success, const char *format, va_list args) __attribute__((__format__(printf, 2, 0))); -void skip(const char *reason, ...) - __attribute__((__format__(printf, 1, 2))); +void skip(const char *reason, ...) __attribute__((__format__(printf, 1, 2))); /* * Report the same status on, or skip, the next count tests. ok_block() @@ -125,10 +124,8 @@ int sysdiag(const char *format, ...) * diag(). Nul characters are not supported in these files and will result in * truncated output. */ -void diag_file_add(const char *file) - __attribute__((__nonnull__)); -void diag_file_remove(const char *file) - __attribute__((__nonnull__)); +void diag_file_add(const char *file) __attribute__((__nonnull__)); +void diag_file_remove(const char *file) __attribute__((__nonnull__)); /* Allocate memory, reporting a fatal error with bail on failure. */ void *bcalloc(size_t, size_t) @@ -144,6 +141,14 @@ char *bstrdup(const char *) char *bstrndup(const char *, size_t) __attribute__((__malloc__, __nonnull__, __warn_unused_result__)); +/* + * Macros that cast the return value from b* memory functions, making them + * usable in C++ code and providing some additional type safety. + */ +#define bcalloc_type(n, type) ((type *) bcalloc((n), sizeof(type))) +#define breallocarray_type(p, n, type) \ + ((type *) breallocarray((p), (n), sizeof(type))) + /* * Find a test file under C_TAP_BUILD or C_TAP_SOURCE, returning the full * path. The returned path should be freed with test_file_path_free(). @@ -156,8 +161,7 @@ void test_file_path_free(char *path); * Create a temporary directory relative to C_TAP_BUILD and return the path. * The returned path should be freed with test_tmpdir_free(). */ -char *test_tmpdir(void) - __attribute__((__malloc__, __warn_unused_result__)); +char *test_tmpdir(void) __attribute__((__malloc__, __warn_unused_result__)); void test_tmpdir_free(char *path); /* @@ -168,10 +172,19 @@ void test_tmpdir_free(char *path); * The function must return void and will be passed two arguments: an int that * will be true if the test completed successfully and false otherwise, and an * int that will be true if the cleanup function is run in the primary process - * (the one that called plan or plan_lazy) and false otherwise. + * (the one that called plan or plan_lazy) and false otherwise. If + * test_cleanup_register_with_data is used instead, a generic pointer can be + * provided and will be passed to the cleanup function as a third argument. + * + * test_cleanup_register_with_data is the better API and should have been the + * only API. test_cleanup_register was an API error preserved for backward + * cmpatibility. */ typedef void (*test_cleanup_func)(int, int); -void test_cleanup_register(test_cleanup_func) +typedef void (*test_cleanup_func_with_data)(int, int, void *); + +void test_cleanup_register(test_cleanup_func) __attribute__((__nonnull__)); +void test_cleanup_register_with_data(test_cleanup_func_with_data, void *) __attribute__((__nonnull__)); END_DECLS diff --git a/tests/tap/kerberos.c b/tests/tap/kerberos.c index 89a36a3..765d802 100644 --- a/tests/tap/kerberos.c +++ b/tests/tap/kerberos.c @@ -42,7 +42,7 @@ #include #ifdef HAVE_KRB5 -# include +# include #endif #include @@ -59,7 +59,7 @@ * to handle the possible patterns for kinit commands as an array. */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || defined(__clang__) -# pragma GCC diagnostic ignored "-Wformat-nonliteral" +# pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif @@ -158,12 +158,11 @@ kerberos_kinit(void) static void kerberos_kinit(void) { - static const char * const format[] = { + static const char *const format[] = { "kinit --no-afslog -k -t %s %s >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 . * * Written by Russ Allbery - * Copyright 2017 Russ Allbery + * Copyright 2017, 2020 Russ Allbery * Copyright 2006-2007, 2009, 2011-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -37,20 +37,20 @@ #include #ifdef HAVE_KRB5 -# include +# include #endif /* Holds the information parsed from the Kerberos test configuration. */ struct kerberos_config { - char *keytab; /* Path to the keytab. */ - char *principal; /* Principal whose keys are in the keytab. */ - char *cache; /* Path to the Kerberos ticket cache. */ - char *userprinc; /* The fully-qualified principal. */ - char *username; /* The local (non-realm) part of principal. */ - char *realm; /* The realm part of the principal. */ - char *password; /* The password. */ - char *pkinit_principal; /* Principal for PKINIT authentication. */ - char *pkinit_cert; /* Path to certificates for PKINIT. */ + char *keytab; /* Path to the keytab. */ + char *principal; /* Principal whose keys are in the keytab. */ + char *cache; /* Path to the Kerberos ticket cache. */ + char *userprinc; /* The fully-qualified principal. */ + char *username; /* The local (non-realm) part of principal. */ + char *realm; /* The realm part of the principal. */ + char *password; /* The password. */ + char *pkinit_principal; /* Principal for PKINIT authentication. */ + char *pkinit_cert; /* Path to certificates for PKINIT. */ }; /* @@ -59,11 +59,13 @@ struct kerberos_config { * tests require both keytab and password, but PKINIT is not required. */ enum kerberos_needs { + /* clang-format off */ TAP_KRB_NEEDS_NONE = 0x00, TAP_KRB_NEEDS_KEYTAB = 0x01, TAP_KRB_NEEDS_PASSWORD = 0x02, TAP_KRB_NEEDS_BOTH = 0x01 | 0x02, TAP_KRB_NEEDS_PKINIT = 0x04 + /* clang-format on */ }; BEGIN_DECLS @@ -106,7 +108,7 @@ void kerberos_cleanup(void); void kerberos_generate_conf(const char *realm); void kerberos_cleanup_conf(void); -/* Thes interfaces are only available with native Kerberos support. */ +/* These interfaces are only available with native Kerberos support. */ #ifdef HAVE_KRB5 /* Bail out with an error, appending the Kerberos error message. */ diff --git a/tests/tap/macros.h b/tests/tap/macros.h index cc6d104..c2c8b5c 100644 --- a/tests/tap/macros.h +++ b/tests/tap/macros.h @@ -42,9 +42,9 @@ * the other attributes to work with GCC versions between 2.7 and 2.96. */ #ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) -# define __attribute__(spec) /* empty */ -# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) +# define __attribute__(spec) /* empty */ +# endif #endif /* @@ -55,18 +55,18 @@ * variadic macro support. */ #if !defined(__attribute__) && !defined(__alloc_size__) -# if defined(__GNUC__) && !defined(__clang__) -# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) -# define __alloc_size__(spec, args...) /* empty */ -# endif -# endif +# if defined(__GNUC__) && !defined(__clang__) +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) +# define __alloc_size__(spec, args...) /* empty */ +# endif +# endif #endif /* Suppress __warn_unused_result__ if gcc is too old. */ #if !defined(__attribute__) && !defined(__warn_unused_result__) -# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) -# define __warn_unused_result__ /* empty */ -# endif +# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) +# define __warn_unused_result__ /* empty */ +# endif #endif /* @@ -76,7 +76,7 @@ * compilation context, but there's no push and pop available. */ #if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) -# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wattributes" #endif /* Used for unused parameters to silence gcc warnings. */ @@ -89,11 +89,11 @@ #undef BEGIN_DECLS #undef END_DECLS #ifdef __cplusplus -# define BEGIN_DECLS extern "C" { -# define END_DECLS } +# define BEGIN_DECLS extern "C" { +# define END_DECLS } #else -# define BEGIN_DECLS /* empty */ -# define END_DECLS /* empty */ +# define BEGIN_DECLS /* empty */ +# define END_DECLS /* empty */ #endif #endif /* TAP_MACROS_H */ diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm index 3b2f584..cd106d0 100644 --- a/tests/tap/perl/Test/RRA.pm +++ b/tests/tap/perl/Test/RRA.pm @@ -10,25 +10,41 @@ package Test::RRA; -use 5.006; +use 5.008; +use base qw(Exporter); use strict; use warnings; -use Exporter; +use Carp qw(croak); use File::Temp; -use Test::More; -# For Perl 5.006 compatibility. -## no critic (ClassHierarchies::ProhibitExplicitISA) +# Abort if Test::More was loaded before Test::RRA to be sure that we get the +# benefits of the Test::More probing below. +if ($INC{'Test/More.pm'}) { + croak('Test::More loaded before Test::RRA'); +} + +# Red Hat's base perl package doesn't include Test::More (one has to install +# the perl-core package in addition). Try to detect this and skip any Perl +# tests if Test::More is not present. This relies on Test::RRA being included +# before Test::More. +eval { + require Test::More; + Test::More->import(); +}; +if ($@) { + print "1..0 # SKIP Test::More required for test\n" + or croak('Cannot write to stdout'); + exit 0; +} # Declare variables that should be set in BEGIN for robustness. -our (@EXPORT_OK, @ISA, $VERSION); +our (@EXPORT_OK, $VERSION); # Set $VERSION and everything export-related in a BEGIN block for robustness # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - @ISA = qw(Exporter); @EXPORT_OK = qw( is_file_contents skip_unless_author skip_unless_automated use_prereq ); @@ -36,7 +52,7 @@ BEGIN { # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '7.02'; + $VERSION = '8.02'; } # Compare a string to the contents of a file, similar to the standard is() @@ -61,22 +77,27 @@ sub is_file_contents { return; } - # Otherwise, we show a diff, but only if we have IPC::System::Simple. - eval { require IPC::System::Simple }; + # Otherwise, we show a diff, but only if we have IPC::System::Simple and + # diff succeeds. Otherwise, we fall back on showing the full expected and + # seen output. + eval { + require IPC::System::Simple; + + my $tmp = File::Temp->new(); + my $tmpname = $tmp->filename; + print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n"); + my @command = ('diff', '-u', $expected, $tmpname); + my $diff = IPC::System::Simple::capturex([0 .. 1], @command); + diag($diff); + }; if ($@) { - ok(0, $message); - return; + diag('Expected:'); + diag($expected); + diag('Seen:'); + diag($data); } - # They're not equal. Write out what we got so that we can run diff. - my $tmp = File::Temp->new(); - my $tmpname = $tmp->filename; - print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n"); - my @command = ('diff', '-u', $expected, $tmpname); - my $diff = IPC::System::Simple::capturex([0 .. 1], @command); - diag($diff); - - # Remove the temporary file and report failure. + # Report failure. ok(0, $message); return; } @@ -91,7 +112,7 @@ sub is_file_contents { sub skip_unless_author { my ($description) = @_; if (!$ENV{AUTHOR_TESTING}) { - plan skip_all => "$description only run for author"; + plan(skip_all => "$description only run for author"); } return; } @@ -110,7 +131,7 @@ sub skip_unless_automated { for my $env (qw(AUTOMATED_TESTING RELEASE_TESTING AUTHOR_TESTING)) { return if $ENV{$env}; } - plan skip_all => "$description normally skipped"; + plan(skip_all => "$description normally skipped"); return; } @@ -152,14 +173,14 @@ sub use_prereq { use $module $version \@imports; 1; }; - $error = $@; + $error = $@; $sigdie = $SIG{__DIE__} || undef; } # If the use failed for any reason, skip the test. if (!$result || $error) { my $name = length($version) > 0 ? "$module $version" : $module; - plan skip_all => "$name required for test"; + plan(skip_all => "$name required for test"); } # If the module set $SIG{__DIE__}, we cleared that via local. Restore it. @@ -202,6 +223,14 @@ This module collects utility functions that are useful for Perl test scripts. It assumes Russ Allbery's Perl module layout and test conventions and will only be useful for other people if they use the same conventions. +This module B be loaded before Test::More or it will abort during +import. It will skip the test (by printing a skip message to standard output +and exiting with status 0, equivalent to C) during import if +Test::More is not available. This allows tests written in Perl using this +module to be skipped if run on a system with Perl but not Test::More, such as +Red Hat systems with the C package but not the C package +installed. + =head1 FUNCTIONS None of these functions are imported by default. The ones used by a script @@ -246,7 +275,7 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2016 Russ Allbery +Copyright 2016, 2018-2019 Russ Allbery Copyright 2013-2014 The Board of Trustees of the Leland Stanford Junior University diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm index 69fff6a..16c9b01 100644 --- a/tests/tap/perl/Test/RRA/Automake.pm +++ b/tests/tap/perl/Test/RRA/Automake.pm @@ -15,13 +15,11 @@ package Test::RRA::Automake; -use 5.006; +use 5.008; +use base qw(Exporter); use strict; use warnings; -# For Perl 5.006 compatibility. -## no critic (ClassHierarchies::ProhibitExplicitISA) - use Exporter; use File::Find qw(find); use File::Spec; @@ -54,13 +52,12 @@ use lib $PERL_BLIB_ARCH; use lib $PERL_BLIB_LIB; # Declare variables that should be set in BEGIN for robustness. -our (@EXPORT_OK, @ISA, $VERSION); +our (@EXPORT_OK, $VERSION); # Set $VERSION and everything export-related in a BEGIN block for robustness # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - @ISA = qw(Exporter); @EXPORT_OK = qw( all_files automake_setup perl_dirs test_file_path test_tmpdir ); @@ -68,13 +65,13 @@ BEGIN { # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '7.02'; + $VERSION = '8.02'; } # Directories to skip globally when looking for all files, or for directories # that could contain Perl files. my @GLOBAL_SKIP = qw( - .git _build autom4te.cache build-aux perl/_build perl/blib + .git .pc _build autom4te.cache build-aux perl/_build perl/blib ); # Additional paths to skip when building a list of all files in the @@ -189,7 +186,7 @@ sub automake_setup { @builddirs = File::Spec->splitdir($builddirs); pop(@builddirs); my $libdir = File::Spec->catdir(@builddirs, $LIBRARY_PATH); - my $path = File::Spec->catpath($buildvol, $libdir, q{}); + my $path = File::Spec->catpath($buildvol, $libdir, q{}); if (-d "$path/.libs") { $path .= '/.libs'; } @@ -229,7 +226,7 @@ sub perl_dirs { } # Convert the skip lists into hashes for convenience. - my %skip = map { $_ => 1 } @skip, 'tests'; + my %skip = map { $_ => 1 } @skip, 'tests'; my %skip_tests = map { $_ => 1 } @skip_tests; # Build the list of top-level directories to test. @@ -451,7 +448,7 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2014-2015, 2018 Russ Allbery +Copyright 2014-2015, 2018-2020 Russ Allbery Copyright 2013 The Board of Trustees of the Leland Stanford Junior University diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm index 40641f1..7064140 100644 --- a/tests/tap/perl/Test/RRA/Config.pm +++ b/tests/tap/perl/Test/RRA/Config.pm @@ -9,24 +9,20 @@ package Test::RRA::Config; -use 5.006; +use 5.008; +use base qw(Exporter); use strict; use warnings; -# For Perl 5.006 compatibility. -## no critic (ClassHierarchies::ProhibitExplicitISA) - -use Exporter; use Test::More; # Declare variables that should be set in BEGIN for robustness. -our (@EXPORT_OK, @ISA, $VERSION); +our (@EXPORT_OK, $VERSION); # Set $VERSION and everything export-related in a BEGIN block for robustness # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - @ISA = qw(Exporter); @EXPORT_OK = qw( $COVERAGE_LEVEL @COVERAGE_SKIP_TESTS @CRITIC_IGNORE $LIBRARY_PATH $MINIMUM_VERSION %MINIMUM_VERSION @MODULE_VERSION_IGNORE @@ -36,7 +32,7 @@ BEGIN { # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '7.02'; + $VERSION = '8.02'; } # If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for @@ -187,7 +183,7 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2015-2016 Russ Allbery +Copyright 2015-2016, 2019 Russ Allbery Copyright 2013-2014 The Board of Trustees of the Leland Stanford Junior University diff --git a/tests/tap/perl/Test/RRA/ModuleVersion.pm b/tests/tap/perl/Test/RRA/ModuleVersion.pm index 8b6dba2..7774351 100644 --- a/tests/tap/perl/Test/RRA/ModuleVersion.pm +++ b/tests/tap/perl/Test/RRA/ModuleVersion.pm @@ -8,32 +8,28 @@ package Test::RRA::ModuleVersion; -use 5.006; +use 5.008; +use base qw(Exporter); use strict; use warnings; -use Exporter; use File::Find qw(find); use Test::More; use Test::RRA::Config qw(@MODULE_VERSION_IGNORE); -# For Perl 5.006 compatibility. -## no critic (ClassHierarchies::ProhibitExplicitISA) - # Declare variables that should be set in BEGIN for robustness. -our (@EXPORT_OK, @ISA, $VERSION); +our (@EXPORT_OK, $VERSION); # Set $VERSION and everything export-related in a BEGIN block for robustness # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - @ISA = qw(Exporter); @EXPORT_OK = qw(test_module_versions update_module_versions); # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '7.02'; + $VERSION = '8.02'; } # A regular expression matching the version string for a module using the @@ -139,7 +135,7 @@ sub _update_module_version { } # Scan for the version and replace it. - open(my $in, q{<}, $file) or die "$0: cannot open $file: $!\n"; + open(my $in, q{<}, $file) or die "$0: cannot open $file: $!\n"; open(my $out, q{>}, "$file.new") or die "$0: cannot create $file.new: $!\n"; SCAN: @@ -155,8 +151,8 @@ sub _update_module_version { # Copy the rest of the input file to the output file. print {$out} <$in> or die "$0: cannot write to $file.new: $!\n"; - close($out) or die "$0: cannot flush $file.new: $!\n"; - close($in) or die "$0: error reading from $file: $!\n"; + close($out) or die "$0: cannot flush $file.new: $!\n"; + close($in) or die "$0: error reading from $file: $!\n"; # All done. Rename the new file over top of the old file. rename("$file.new", $file) @@ -269,7 +265,7 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2016, 2018 Russ Allbery +Copyright 2016, 2018-2019 Russ Allbery Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/tests/tap/process.c b/tests/tap/process.c index d9e94d8..2f797f8 100644 --- a/tests/tap/process.c +++ b/tests/tap/process.c @@ -46,11 +46,11 @@ #include #include #ifdef HAVE_SYS_SELECT_H -# include +# include #endif #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include #include @@ -61,7 +61,7 @@ /* May be defined by the build system. */ #ifndef PATH_FAKEROOT -# define PATH_FAKEROOT "" +# define PATH_FAKEROOT "" #endif /* How long to wait for the process to start in seconds. */ @@ -72,12 +72,12 @@ * everything required to stop the process and clean up after it. */ struct process { - pid_t pid; /* PID of child process */ - char *pidfile; /* PID file to delete on process stop */ - char *tmpdir; /* Temporary directory for log file */ - char *logfile; /* Log file of process output */ - bool is_child; /* Whether we can waitpid for process */ - struct process *next; /* Next process in global list */ + pid_t pid; /* PID of child process */ + char *pidfile; /* PID file to delete on process stop */ + char *tmpdir; /* Temporary directory for log file */ + char *logfile; /* Log file of process output */ + bool is_child; /* Whether we can waitpid for process */ + struct process *next; /* Next process in global list */ }; /* diff --git a/tests/tap/process.h b/tests/tap/process.h index da21ad3..4210c20 100644 --- a/tests/tap/process.h +++ b/tests/tap/process.h @@ -62,8 +62,7 @@ void is_function_output(test_function_type, void *data, int status, * successfully, call bail, with the error message being the output from the * program. */ -void run_setup(const char *const argv[]) - __attribute__((__nonnull__)); +void run_setup(const char *const argv[]) __attribute__((__nonnull__)); /* * process_start starts a process in the background, returning an opaque data diff --git a/tests/tap/string.h b/tests/tap/string.h index a520210..651c38a 100644 --- a/tests/tap/string.h +++ b/tests/tap/string.h @@ -36,7 +36,7 @@ #include #include -#include /* va_list */ +#include /* va_list */ BEGIN_DECLS diff --git a/tests/util/messages-krb5-t.c b/tests/util/messages-krb5-t.c index b22c4cf..e68c57f 100644 --- a/tests/util/messages-krb5-t.c +++ b/tests/util/messages-krb5-t.c @@ -5,6 +5,7 @@ * which can be found at . * * Written by Russ Allbery + * Copyright 2020 Russ Allbery * Copyright 2010-2011, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -31,7 +32,7 @@ #include #ifdef HAVE_KRB5 -# include +# include #endif #include @@ -39,7 +40,7 @@ #include #include #ifdef HAVE_KRB5 -# include +# include #endif #include #include @@ -58,7 +59,7 @@ main(void) /* * Test functions. */ -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test_warn(void *data UNUSED) { krb5_context ctx; @@ -76,7 +77,7 @@ test_warn(void *data UNUSED) exit(0); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test_die(void *data UNUSED) { krb5_context ctx; diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c index e8a7835..cfb661a 100644 --- a/tests/util/messages-t.c +++ b/tests/util/messages-t.c @@ -5,7 +5,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2002, 2004-2005, 2015, 2017 Russ Allbery + * Copyright 2002, 2004-2005, 2015, 2017, 2020 Russ Allbery * Copyright 2009-2012 * The Board of Trustees of the Leland Stanford Junior University * @@ -54,7 +54,7 @@ test1(void *data UNUSED) warn("warning"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test2(void *data UNUSED) { die("fatal"); @@ -67,7 +67,7 @@ test3(void *data UNUSED) syswarn("permissions"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test4(void *data UNUSED) { errno = EACCES; @@ -81,7 +81,7 @@ test5(void *data UNUSED) warn("warning"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test6(void *data UNUSED) { message_program_name = "test6"; @@ -96,7 +96,7 @@ test7(void *data UNUSED) syswarn("perms %d", 7); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test8(void *data UNUSED) { message_program_name = "test8"; @@ -110,14 +110,14 @@ return10(void) return 10; } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test9(void *data UNUSED) { message_fatal_cleanup = return10; die("fatal"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test10(void *data UNUSED) { message_program_name = 0; @@ -126,7 +126,7 @@ test10(void *data UNUSED) sysdie("fatal perm"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test11(void *data UNUSED) { message_program_name = "test11"; @@ -136,7 +136,7 @@ test11(void *data UNUSED) sysdie("fatal"); } -static void __attribute__((__format__(printf, 2, 0))) +__attribute__((__format__(printf, 2, 0))) static void log_msg(size_t len, const char *format, va_list args, int error) { fprintf(stderr, "%lu %d ", (unsigned long) len, error); @@ -151,7 +151,7 @@ test12(void *data UNUSED) warn("warning"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test13(void *data UNUSED) { message_handlers_die(1, log_msg); @@ -166,7 +166,7 @@ test14(void *data UNUSED) syswarn("warning"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test15(void *data UNUSED) { message_handlers_die(2, log_msg, log_msg); @@ -218,22 +218,22 @@ test21(void *data UNUSED) debug("baz"); } -static void __attribute__((__noreturn__)) +__attribute__((__noreturn__)) static void test22(void *data UNUSED) { message_handlers_die(0); die("hi mom!"); } -static -void test23(void *data UNUSED) +static void +test23(void *data UNUSED) { message_handlers_warn(0); warn("this is a test"); } -static -void test24(void *data UNUSED) +static void +test24(void *data UNUSED) { notice("first"); message_handlers_notice(0); @@ -305,7 +305,7 @@ main(void) is_function_output(test20, NULL, 0, "3 0 foo\n", "test20"); is_function_output(test21, NULL, 0, "test23: baz\n", "test21"); - /* Make sure that it's possible to turn off a message type entirely. */ + /* Make sure that it's possible to turn off a message type entirely. */ is_function_output(test22, NULL, 1, "", "test22"); is_function_output(test23, NULL, 0, "", "test23"); is_function_output(test24, NULL, 0, "first\nthird\n", "test24"); diff --git a/tests/util/xmalloc-t b/tests/util/xmalloc-t index e73a7c6..b3afa31 100755 --- a/tests/util/xmalloc-t +++ b/tests/util/xmalloc-t @@ -6,7 +6,8 @@ # which can be found at . # # Written by Russ Allbery -# Copyright 2000-2001, 2006, 2014, 2016 Russ Allbery +# Copyright 2000-2001, 2006, 2014, 2016, 2019-2020 +# Russ Allbery # Copyright 2008-2010, 2012 # The Board of Trustees of the Leland Stanford Junior University # @@ -33,7 +34,7 @@ . "$C_TAP_SOURCE/tap/libtap.sh" cd "$C_TAP_BUILD/util" -# Run an xmalloc test. Takes the description, the expectd exit status, the +# Run an xmalloc test. Takes the description, the expected exit status, the # output, and the arguments. ok_xmalloc () { local desc w_status w_output output status @@ -101,46 +102,46 @@ ok_xmalloc "vasprintf large" 0 "" "v" "30000000" "0" # We assume that there are enough miscellaneous allocations that an allocation # exactly as large as the limit will always fail. ok_xmalloc "malloc fail" 1 \ - "failed to malloc 30000000 bytes at xmalloc.c line 41" \ + "failed to malloc 30000000 bytes at xmalloc.c line 42" \ "m" "30000000" "30000000" ok_xmalloc "realloc fail" 1 \ - "failed to realloc 30000000 bytes at xmalloc.c line 69" \ + "failed to realloc 30000000 bytes at xmalloc.c line 71" \ "r" "30000000" "30000000" ok_xmalloc "reallocarray fail" 1 \ - "failed to reallocarray 30000000 bytes at xmalloc.c line 99" \ + "failed to reallocarray 30000000 bytes at xmalloc.c line 100" \ "y" "30000000" "30000000" ok_xmalloc "strdup fail" 1 \ - "failed to strdup 30000000 bytes at xmalloc.c line 130" \ + "failed to strdup 30000000 bytes at xmalloc.c line 131" \ "s" "30000000" "30000000" ok_xmalloc "strndup fail" 1 \ - "failed to strndup 30000000 bytes at xmalloc.c line 176" \ + "failed to strndup 30000000 bytes at xmalloc.c line 177" \ "n" "30000000" "30000000" ok_xmalloc "calloc fail" 1 \ - "failed to calloc 30000000 bytes at xmalloc.c line 200" \ + "failed to calloc 30000000 bytes at xmalloc.c line 201" \ "c" "30000000" "30000000" ok_xmalloc "asprintf fail" 1 \ - "failed to asprintf 30000000 bytes at xmalloc.c line 224" \ + "failed to asprintf 30000000 bytes at xmalloc.c line 225" \ "a" "30000000" "30000000" ok_xmalloc "vasprintf fail" 1 \ - "failed to vasprintf 30000000 bytes at xmalloc.c line 243" \ + "failed to vasprintf 30000000 bytes at xmalloc.c line 244" \ "v" "30000000" "30000000" # Check our custom error handler. -ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 41" \ +ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 42" \ "M" "30000000" "30000000" -ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 69" \ +ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 71" \ "R" "30000000" "30000000" -ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 99" \ +ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 100" \ "Y" "30000000" "30000000" -ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 130" \ +ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 131" \ "S" "30000000" "30000000" -ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 176" \ +ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 177" \ "N" "30000000" "30000000" -ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 200" \ +ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 201" \ "C" "30000000" "30000000" -ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 224" \ +ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 225" \ "A" "30000000" "30000000" -ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 243" \ +ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 244" \ "V" "30000000" "30000000" # Check the smaller ones again just for grins. diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c index d157bbb..eb6f1d2 100644 --- a/tests/util/xmalloc.c +++ b/tests/util/xmalloc.c @@ -4,7 +4,7 @@ * The canonical version of this file is maintained in the rra-c-util package, * which can be found at . * - * Copyright 2000-2001, 2006, 2017 Russ Allbery + * Copyright 2000-2001, 2006, 2017, 2020 Russ Allbery * Copyright 2008, 2012-2014 * The Board of Trustees of the Leland Stanford Junior University * @@ -34,10 +34,11 @@ #include #include +#include #include #include #ifdef HAVE_SYS_TIME_H -# include +# include #endif #include @@ -94,6 +95,7 @@ test_realloc(size_t size) char *buffer; size_t i; + assert(size > 10); buffer = xmalloc(10); if (buffer == NULL) return 0; @@ -101,8 +103,7 @@ test_realloc(size_t size) buffer = xrealloc(buffer, size); if (buffer == NULL) return 0; - if (size > 0) - memset(buffer + 10, 2, size - 10); + memset(buffer + 10, 2, size - 10); for (i = 0; i < 10; i++) if (buffer[i] != 1) return 0; @@ -383,6 +384,7 @@ main(int argc, char *argv[]) #endif } + /* clang-format off */ switch (code) { case 'c': exit(test_calloc(size) ? willfail : 1); case 'm': exit(test_malloc(size) ? willfail : 1); @@ -394,5 +396,7 @@ main(int argc, char *argv[]) case 'v': exit(test_vasprintf(size) ? willfail : 1); default: die("Unknown mode %c", argv[1][0]); } + /* clang-format on */ + exit(1); } diff --git a/util/messages-krb5.c b/util/messages-krb5.c index a33d77a..435369e 100644 --- a/util/messages-krb5.c +++ b/util/messages-krb5.c @@ -37,8 +37,8 @@ #include #include -#include #include +#include #include diff --git a/util/messages.c b/util/messages.c index 941a88f..0e79a43 100644 --- a/util/messages.c +++ b/util/messages.c @@ -54,7 +54,7 @@ * which can be found at . * * Written by Russ Allbery - * Copyright 2015-2016 Russ Allbery + * Copyright 2015-2016, 2020 Russ Allbery * Copyright 2008-2010, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC") @@ -83,17 +83,17 @@ #include #ifdef HAVE_SYSLOG_H -# include +# include #endif #ifdef _WIN32 -# include -# define LOG_DEBUG EVENTLOG_SUCCESS -# define LOG_INFO EVENTLOG_INFORMATION_TYPE -# define LOG_NOTICE EVENTLOG_INFORMATION_TYPE -# define LOG_WARNING EVENTLOG_WARNING_TYPE -# define LOG_ERR EVENTLOG_ERROR_TYPE -# define LOG_CRIT EVENTLOG_ERROR_TYPE +# include +# define LOG_DEBUG EVENTLOG_SUCCESS +# define LOG_INFO EVENTLOG_INFORMATION_TYPE +# define LOG_NOTICE EVENTLOG_INFORMATION_TYPE +# define LOG_WARNING EVENTLOG_WARNING_TYPE +# define LOG_ERR EVENTLOG_ERROR_TYPE +# define LOG_CRIT EVENTLOG_ERROR_TYPE #endif #include @@ -101,18 +101,14 @@ #include /* The default handler lists. */ -static message_handler_func stdout_handlers[2] = { - message_log_stdout, NULL -}; -static message_handler_func stderr_handlers[2] = { - message_log_stderr, NULL -}; +static message_handler_func stdout_handlers[2] = {message_log_stdout, NULL}; +static message_handler_func stderr_handlers[2] = {message_log_stderr, NULL}; /* The list of logging functions currently in effect. */ -static message_handler_func *debug_handlers = NULL; +static message_handler_func *debug_handlers = NULL; static message_handler_func *notice_handlers = stdout_handlers; -static message_handler_func *warn_handlers = stderr_handlers; -static message_handler_func *die_handlers = stderr_handlers; +static message_handler_func *warn_handlers = stderr_handlers; +static message_handler_func *die_handlers = stderr_handlers; /* If non-NULL, called before exit and its return value passed to exit. */ int (*message_fatal_cleanup)(void) = NULL; @@ -144,16 +140,18 @@ message_handlers(message_handler_func **list, unsigned int count, va_list args) * duplication since we can't assume variadic macros, but I can at least make * it easier to write and keep them consistent. */ -#define HANDLER_FUNCTION(type) \ - void \ - message_handlers_ ## type(unsigned int count, ...) \ - { \ - va_list args; \ - \ - va_start(args, count); \ - message_handlers(& type ## _handlers, count, args); \ - va_end(args); \ +/* clang-format off */ +#define HANDLER_FUNCTION(type) \ + void \ + message_handlers_ ## type(unsigned int count, ...) \ + { \ + va_list args; \ + \ + va_start(args, count); \ + message_handlers(& type ## _handlers, count, args); \ + va_end(args); \ } +/* clang-format on */ HANDLER_FUNCTION(debug) HANDLER_FUNCTION(notice) HANDLER_FUNCTION(warn) @@ -254,7 +252,7 @@ message_log_syslog(int pri, size_t len, const char *fmt, va_list args, int err) CloseEventLog(eventlog); } } -#else /* !_WIN32 */ +#else /* !_WIN32 */ if (err == 0) syslog(pri, "%s", buffer); else @@ -268,6 +266,7 @@ message_log_syslog(int pri, size_t len, const char *fmt, va_list args, int err) * Do the same sort of wrapper to generate all of the separate syslog logging * functions. */ +/* clang-format off */ #define SYSLOG_FUNCTION(name, type) \ void \ message_log_syslog_ ## name(size_t l, const char *f, va_list a, int e) \ @@ -280,6 +279,7 @@ SYSLOG_FUNCTION(notice, NOTICE) SYSLOG_FUNCTION(warning, WARNING) SYSLOG_FUNCTION(err, ERR) SYSLOG_FUNCTION(crit, CRIT) +/* clang-format on */ /* diff --git a/util/xmalloc.c b/util/xmalloc.c index f5cacc3..e8a9a82 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -101,8 +101,8 @@ void xmalloc_fail(const char *function, size_t size, const char *file, int line) { if (size == 0) - sysdie("failed to format output with %s at %s line %d", function, - file, line); + sysdie("failed to format output with %s at %s line %d", function, file, + line); else sysdie("failed to %s %lu bytes at %s line %d", function, (unsigned long) size, file, line); @@ -202,7 +202,7 @@ x_strndup(const char *s, size_t size, const char *file, int line) char *copy; /* Don't assume that the source string is nul-terminated. */ - for (p = s; (size_t) (p - s) < size && *p != '\0'; p++) + for (p = s; (size_t)(p - s) < size && *p != '\0'; p++) ; length = p - s; copy = malloc(length + 1); @@ -262,7 +262,7 @@ x_asprintf(char **strp, const char *file, int line, const char *fmt, ...) } va_end(args); } -#else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */ +#else /* !(HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS) */ void x_asprintf(char **strp, const char *fmt, ...) { diff --git a/util/xmalloc.h b/util/xmalloc.h index 61f5ed1..02c5431 100644 --- a/util/xmalloc.h +++ b/util/xmalloc.h @@ -42,12 +42,12 @@ * number information for debugging error messages without the user having to * pass those in every time. */ -#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__) -#define xmalloc(size) x_malloc((size), __FILE__, __LINE__) -#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__) -#define xstrdup(p) x_strdup((p), __FILE__, __LINE__) -#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__) -#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__) +#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__) +#define xmalloc(size) x_malloc((size), __FILE__, __LINE__) +#define xrealloc(p, size) x_realloc((p), (size), __FILE__, __LINE__) +#define xstrdup(p) x_strdup((p), __FILE__, __LINE__) +#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__) +#define xvasprintf(p, f, a) x_vasprintf((p), (f), (a), __FILE__, __LINE__) #define xreallocarray(p, n, size) \ x_reallocarray((p), (n), (size), __FILE__, __LINE__) @@ -60,13 +60,13 @@ * are supported. */ #ifdef HAVE_C99_VAMACROS -# define xasprintf(p, f, ...) \ - x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__) +# define xasprintf(p, f, ...) \ + x_asprintf((p), __FILE__, __LINE__, (f), __VA_ARGS__) #elif HAVE_GNU_VAMACROS -# define xasprintf(p, f, args...) \ - x_asprintf((p), __FILE__, __LINE__, (f), args) +# define xasprintf(p, f, args...) \ + x_asprintf((p), __FILE__, __LINE__, (f), args) #else -# define xasprintf x_asprintf +# define xasprintf x_asprintf #endif BEGIN_DECLS -- cgit v1.2.3