From bdcb3741db27d6b773ce7cdf05aab063a70ea100 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 27 May 2018 20:59:59 -0700 Subject: Update to rra-c-util 7.2 and C TAP Harness 4.3 Update to rra-c-util 7.2: * Improve configure output for krb5-config testing. * Define UINT32_MAX for systems that don't have it. * Add SPDX-License-Identifier headers to all substantial source files. * Fix new warnings from GCC 7 and Clang warnings. * Require Test::Strict 0.25 or later to run those tests. * Fix off-by-one error in return-value checks for snprintf. * Use Autoconf to probe for supported warning flags. * Fix running module-version-t -u with current versions of Perl. * Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD. Update to C TAP Harness 4.3: * Add support for valgrind and libtool in test lists. * Report test failures as left and right, not wanted and expected. * Fix string comparisons with NULL pointers and the string "(null)". * Add SPDX-License-Identifier headers to all substantial source files. * Avoid zero-length realloc allocations in breallocarray. * Fix new warnings from GCC 7 and Clang warnings. * Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD. --- Makefile.am | 45 ++--- NEWS | 22 ++ client/internal.h | 5 +- client/options.c | 11 +- client/wallet-rekey.c | 8 +- client/wallet.c | 10 +- configure.ac | 24 ++- m4/cc-flags.m4 | 112 +++++++++++ m4/clang.m4 | 4 +- m4/gssapi.m4 | 6 +- m4/krb5-config.m4 | 13 +- m4/krb5.m4 | 6 +- m4/lib-depends.m4 | 6 +- m4/lib-pathname.m4 | 6 +- m4/remctl.m4 | 6 +- m4/snprintf.m4 | 6 +- m4/vamacros.m4 | 6 +- 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 | 12 +- portable/asprintf.c | 18 +- portable/dummy.c | 20 +- portable/krb5-extra.c | 23 ++- portable/krb5-profile.c | 237 ++++++++++++++++++++++ portable/krb5.h | 30 ++- portable/macros.h | 18 +- portable/mkstemp.c | 17 +- portable/reallocarray.c | 24 ++- portable/setenv.c | 18 +- portable/snprintf.c | 117 ++++++----- portable/stdbool.h | 17 +- portable/system.h | 29 ++- portable/uio.h | 17 +- tests/HOWTO | 248 ----------------------- tests/README | 252 +++++++++++++++++++++++ tests/client/basic-t.in | 15 +- tests/client/full-t.in | 23 ++- tests/client/prompt-t.in | 23 ++- tests/client/rekey-t.in | 15 +- tests/data/cmd-wrapper | 5 +- tests/docs/pod-spelling-t | 9 +- tests/docs/pod-t | 9 +- tests/perl/minimum-version-t | 9 +- tests/perl/module-version-t | 14 +- tests/perl/strict-t | 11 +- tests/portable/asprintf-t.c | 23 ++- tests/portable/mkstemp-t.c | 17 +- tests/portable/setenv-t.c | 18 +- tests/portable/snprintf-t.c | 11 +- tests/runtests.c | 331 ++++++++++++++++++++++++------- tests/server/admin-t | 5 +- tests/server/backend-t | 5 +- tests/server/keytab-t | 9 +- tests/server/report-t | 5 +- tests/tap/basic.c | 136 +++++++++---- tests/tap/basic.h | 34 ++-- tests/tap/kerberos.c | 35 ++-- tests/tap/kerberos.h | 15 +- tests/tap/kerberos.sh | 10 +- tests/tap/libtap.sh | 28 +-- tests/tap/macros.h | 4 +- tests/tap/messages.c | 9 +- tests/tap/messages.h | 7 +- tests/tap/perl/Test/RRA.pm | 57 +++++- tests/tap/perl/Test/RRA/Automake.pm | 189 +++++++++++++----- tests/tap/perl/Test/RRA/Config.pm | 36 ++-- tests/tap/perl/Test/RRA/ModuleVersion.pm | 10 +- tests/tap/process.c | 16 +- tests/tap/process.h | 6 +- tests/tap/remctl.sh | 9 +- tests/tap/string.c | 6 +- tests/tap/string.h | 6 +- tests/util/messages-krb5-t.c | 10 +- tests/util/messages-t.c | 145 +++++++++++--- tests/util/xmalloc-t | 12 +- tests/util/xmalloc.c | 16 +- util/macros.h | 18 +- util/messages-krb5.c | 6 +- util/messages-krb5.h | 10 +- util/messages.c | 15 +- util/messages.h | 14 +- util/xmalloc.c | 13 +- util/xmalloc.h | 15 +- 84 files changed, 1952 insertions(+), 903 deletions(-) create mode 100644 m4/cc-flags.m4 create mode 100644 portable/krb5-profile.c delete mode 100644 tests/HOWTO create mode 100644 tests/README diff --git a/Makefile.am b/Makefile.am index 4fb0b06..eb9ba7e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ # Automake makefile for wallet. # # Written by Russ Allbery -# Copyright 2016 Russ Allbery -# Copyright 2006, 2007, 2008, 2010, 2013, 2014 +# Copyright 2016, 2018 Russ Allbery +# Copyright 2006-2008, 2010, 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. @@ -134,9 +134,9 @@ EXTRA_DIST = .gitignore .travis.yml LICENSE autogen client/wallet.pod \ # Supporting convenience libraries used by other targets. noinst_LIBRARIES = portable/libportable.a util/libutil.a -portable_libportable_a_SOURCES = portable/dummy.c portable/krb5-extra.c \ - portable/krb5.h portable/macros.h portable/stdbool.h \ - portable/system.h portable/uio.h +portable_libportable_a_SOURCES = portable/dummy.c portable/krb5.h \ + portable/macros.h portable/stdbool.h portable/system.h \ + portable/uio.h portable_libportable_a_CPPFLAGS = $(KRB5_CPPFLAGS) portable_libportable_a_LIBADD = $(LIBOBJS) util_libutil_a_SOURCES = util/macros.h util/messages-krb5.c \ @@ -182,32 +182,12 @@ dist_pkgdata_DATA = perl/sql/Wallet-Schema-0.07-0.08-MySQL.sql \ perl/sql/Wallet-Schema-0.09-PostgreSQL.sql \ perl/sql/Wallet-Schema-0.09-SQLite.sql -# A set of flags for warnings. Add -O because gcc won't find some warnings -# without optimization turned on. Desirable warnings that can't be turned -# on due to other problems: -# -# -Wconversion http://bugs.debian.org/488884 (htons warnings) -# -# Last checked against gcc 4.8.2 (2014-04-12). -D_FORTIFY_SOURCE=2 enables -# warn_unused_result attribute markings on glibc functions on Linux, which -# catches a few more issues. -if WARNINGS_GCC - WARNINGS = -g -O -fstrict-overflow -fstrict-aliasing -D_FORTIFY_SOURCE=2 \ - -Wall -Wextra -Wendif-labels -Wformat=2 -Winit-self -Wswitch-enum \ - -Wstrict-overflow=5 -Wmissing-format-attribute -Wfloat-equal \ - -Wdeclaration-after-statement -Wshadow -Wpointer-arith \ - -Wbad-function-cast -Wcast-align -Wwrite-strings -Wjump-misses-init \ - -Wlogical-op -Wstrict-prototypes -Wold-style-definition \ - -Wmissing-prototypes -Wnormalized=nfc -Wpacked -Wredundant-decls \ - -Wnested-externs -Winline -Wvla -Werror -endif -if WARNINGS_CLANG - WARNINGS = -Weverything -Wno-padded -endif - +# Separate target for a human to request building everything with as many +# compiler warnings enabled as possible. warnings: - $(MAKE) V=0 CFLAGS='$(WARNINGS)' KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' - $(MAKE) V=0 CFLAGS='$(WARNINGS)' \ + $(MAKE) V=0 CFLAGS='$(WARNINGS_CFLAGS) $(AM_CFLAGS)' \ + KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' + $(MAKE) V=0 CFLAGS='$(WARNINGS_CFLAGS) $(AM_CFLAGS)' \ KRB5_CPPFLAGS='$(KRB5_CPPFLAGS_GCC)' $(check_PROGRAMS) # Remove some additional files. @@ -272,7 +252,6 @@ install-data-local: esac ; \ cd perl && ./Build install $$flags --destdir '$(DESTDIR)' -# ExtUtils::MakeMaker really likes moving the Makefile aside. clean-local: set -e; if [ -f "perl/Build" ] ; then \ cd perl && ./Build realclean ; \ @@ -293,8 +272,8 @@ check_PROGRAMS = tests/runtests tests/portable/asprintf-t \ tests/portable/mkstemp-t tests/portable/setenv-t \ tests/portable/snprintf-t tests/util/messages-krb5-t \ tests/util/messages-t tests/util/xmalloc -tests_runtests_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \ - -DBUILD='"$(abs_top_builddir)/tests"' +tests_runtests_CPPFLAGS = -DC_TAP_SOURCE='"$(abs_top_srcdir)/tests"' \ + -DC_TAP_BUILD='"$(abs_top_builddir)/tests"' check_LIBRARIES = tests/tap/libtap.a tests_tap_libtap_a_CPPFLAGS = -I$(abs_top_srcdir)/tests $(KRB5_CPPFLAGS) tests_tap_libtap_a_SOURCES = tests/tap/basic.c tests/tap/basic.h \ diff --git a/NEWS b/NEWS index d8c66b2..2bfedde 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,28 @@ wallet 1.4 (unreleased) for all Perl scripts. This allows wallet to use a version of Perl at a non-standard path. Patches from Karl Kornel. + Update to rra-c-util 7.2: + + * Improve configure output for krb5-config testing. + * Define UINT32_MAX for systems that don't have it. + * Add SPDX-License-Identifier headers to all substantial source files. + * Fix new warnings from GCC 7 and Clang warnings. + * Require Test::Strict 0.25 or later to run those tests. + * Fix off-by-one error in return-value checks for snprintf. + * Use Autoconf to probe for supported warning flags. + * Fix running module-version-t -u with current versions of Perl. + * Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD. + + Update to C TAP Harness 4.3: + + * Add support for valgrind and libtool in test lists. + * Report test failures as left and right, not wanted and expected. + * Fix string comparisons with NULL pointers and the string "(null)". + * Add SPDX-License-Identifier headers to all substantial source files. + * Avoid zero-length realloc allocations in breallocarray. + * Fix new warnings from GCC 7 and Clang warnings. + * Use C_TAP_SOURCE and C_TAP_BUILD instead of SOURCE and BUILD. + wallet 1.3 (2016-01-17) This release adds initial, experimental support for using Active diff --git a/client/internal.h b/client/internal.h index fc0591f..7f58e33 100644 --- a/client/internal.h +++ b/client/internal.h @@ -2,7 +2,8 @@ * Internal support functions for the wallet client. * * Written by Russ Allbery - * Copyright 2007, 2008, 2010 + * Copyright 2018 Russ Allbery + * Copyright 2007-2008, 2010 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. @@ -41,7 +42,7 @@ struct options { char *server; char *principal; char *user; - int port; + unsigned short port; }; BEGIN_DECLS diff --git a/client/options.c b/client/options.c index ae88485..3c68cc7 100644 --- a/client/options.c +++ b/client/options.c @@ -5,7 +5,8 @@ * file for both wallet and wallet-rekey. * * Written by Russ Allbery - * Copyright 2006, 2007, 2008, 2010 + * Copyright 2018 Russ Allbery + * Copyright 2006-2008, 2010 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. @@ -63,9 +64,15 @@ default_number(krb5_context ctx, const char *opt, int defval, int *result) void default_options(krb5_context ctx, struct options *options) { + int port; + default_string(ctx, "wallet_type", "wallet", &options->type); default_string(ctx, "wallet_server", WALLET_SERVER, &options->server); default_string(ctx, "wallet_principal", NULL, &options->principal); - default_number(ctx, "wallet_port", WALLET_PORT, &options->port); + default_number(ctx, "wallet_port", WALLET_PORT, &port); + if (port <= 0 || port > 65535) + options->port = WALLET_PORT; + else + options->port = (unsigned short) port; options->user = NULL; } diff --git a/client/wallet-rekey.c b/client/wallet-rekey.c index 95cd328..2809efc 100644 --- a/client/wallet-rekey.c +++ b/client/wallet-rekey.c @@ -3,6 +3,7 @@ * * Written by Russ Allbery * and Jon Robertson + * Copyright 2018 Russ Allbery * Copyright 2010 * The Board of Trustees of the Leland Stanford Junior University * @@ -40,7 +41,7 @@ Options:\n\ /* * Display the usage message for wallet-rekey. */ -static void +static void __attribute__((__noreturn__)) usage(int status) { fprintf((status == 0) ? stdout : stderr, usage_message, WALLET_PORT, @@ -83,13 +84,12 @@ main(int argc, char *argv[]) break; case 'h': usage(0); - break; case 'p': errno = 0; tmp = strtol(optarg, &end, 10); if (tmp <= 0 || tmp > 65535 || *end != '\0') die("invalid port number %s", optarg); - options.port = tmp; + options.port = (unsigned short) tmp; break; case 's': options.server = optarg; @@ -100,10 +100,8 @@ main(int argc, char *argv[]) case 'v': printf("%s\n", PACKAGE_STRING); exit(0); - break; default: usage(1); - break; } } argc -= optind; diff --git a/client/wallet.c b/client/wallet.c index c3b039f..ed6c9b8 100644 --- a/client/wallet.c +++ b/client/wallet.c @@ -2,7 +2,8 @@ * The client program for the wallet system. * * Written by Russ Allbery - * Copyright 2006, 2007, 2008, 2010, 2014 + * Copyright 2018 Russ Allbery + * Copyright 2006-2008, 2010, 2014 * The Board of Trustees of the Leland Stanford Junior University * * See LICENSE for licensing terms. @@ -44,7 +45,7 @@ Options:\n\ /* * Display the usage message for wallet. */ -static void +static void __attribute__((__noreturn__)) usage(int status) { fprintf((status == 0) ? stdout : stderr, usage_message, WALLET_PORT, @@ -93,13 +94,12 @@ main(int argc, char *argv[]) break; case 'h': usage(0); - break; case 'p': errno = 0; tmp = strtol(optarg, &end, 10); if (tmp <= 0 || tmp > 65535 || *end != '\0') die("invalid port number %s", optarg); - options.port = tmp; + options.port = (unsigned short) tmp; break; case 'S': srvtab = optarg; @@ -113,10 +113,8 @@ main(int argc, char *argv[]) case 'v': printf("%s\n", PACKAGE_STRING); exit(0); - break; default: usage(1); - break; } } argc -= optind; diff --git a/configure.ac b/configure.ac index 0bccef0..c912b3c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,15 @@ dnl Autoconf configuration for wallet. dnl dnl Written by Russ Allbery -dnl Copyright 2014, 2016 Russ Allbery -dnl Copyright 2006, 2007, 2008, 2010, 2013, 2014 +dnl Copyright 2014, 2016, 2018 Russ Allbery +dnl Copyright 2006-2008, 2010, 2013-2014 dnl The Board of Trustees of the Leland Stanford Junior University dnl -dnl See LICENSE for licensing terms. +dnl This file is free software; the authors give unlimited permission to copy +dnl and/or distribute it, with or without modifications, as long as this +dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR AC_PREREQ([2.64]) AC_INIT([wallet], [1.3], [eagle@eyrie.org]) @@ -17,13 +21,14 @@ AM_INIT_AUTOMAKE([1.11 check-news dist-xz foreign silent-rules subdir-objects AM_MAINTAINER_MODE dnl Detect unexpanded macros. +m4_pattern_forbid([^PKG_]) m4_pattern_forbid([^_?RRA_]) dnl AM_PROG_AR is required for Automake 1.12 by Libtool but not defined at all dnl (or needed) in Automake 1.11. Work around this bug. AC_PROG_CC AC_USE_SYSTEM_EXTENSIONS -RRA_PROG_CC_CLANG +RRA_PROG_CC_WARNINGS_FLAGS AC_SYS_LARGEFILE AM_PROG_CC_C_O m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) @@ -65,11 +70,16 @@ AC_CHECK_FUNCS([krb5_get_init_creds_opt_free], AC_CHECK_DECLS([krb5_kt_free_entry], [], [], [RRA_INCLUDES_KRB5]) AC_CHECK_DECLS([krb5_kt_free_entry]) AC_CHECK_MEMBERS([krb5_keytab_entry.keyblock], [], [], [RRA_INCLUDES_KRB5]) +AC_CHECK_FUNCS([krb5_appdefault_string], [], + [AC_CHECK_FUNCS([krb5_get_profile]) + AC_CHECK_HEADERS([k5profile.h profile.h]) + AC_LIBOBJ([krb5-profile])]) +AC_LIBOBJ([krb5-extra]) RRA_LIB_KRB5_RESTORE dnl Probe for properties of the C library. AC_HEADER_STDBOOL -AC_CHECK_HEADERS([sys/bitypes.h sys/uio.h sys/time.h syslog.h]) +AC_CHECK_HEADERS([strings.h sys/bitypes.h sys/uio.h sys/time.h syslog.h]) AC_CHECK_DECLS([snprintf, vsnprintf]) RRA_C_C99_VAMACROS RRA_C_GNU_VAMACROS @@ -87,10 +97,6 @@ AS_IF([test x"$REMCTLD" != x], [AC_DEFINE_UNQUOTED([PATH_REMCTLD], ["$REMCTLD"], [Define to the full path to remctld to run remctl tests.])]) -dnl Enable appropriate warnings. -AM_CONDITIONAL([WARNINGS_GCC], [test x"$GCC" = xyes && test x"$CLANG" != xyes]) -AM_CONDITIONAL([WARNINGS_CLANG], [test x"$CLANG" = xyes]) - dnl Output section. AC_CONFIG_HEADER([config.h]) AC_CONFIG_FILES([Makefile]) diff --git a/m4/cc-flags.m4 b/m4/cc-flags.m4 new file mode 100644 index 0000000..8a5aa8a --- /dev/null +++ b/m4/cc-flags.m4 @@ -0,0 +1,112 @@ +dnl Check whether the compiler supports particular flags. +dnl +dnl Provides RRA_PROG_CC_FLAG, which checks whether a compiler supports a +dnl given flag. If it does, the commands in the second argument are run. If +dnl not, the commands in the third argument are run. +dnl +dnl Provides RRA_PROG_CC_WARNINGS_FLAGS, which checks whether a compiler +dnl supports a large set of warning flags and sets the WARNINGS_CFLAGS +dnl substitution variable to all of the supported warning flags. (Note that +dnl this may be too aggressive for some people.) +dnl +dnl Depends on RRA_PROG_CC_CLANG. +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 2006, 2009, 2016 +dnl by Internet Systems Consortium, Inc. ("ISC") +dnl +dnl Permission to use, copy, modify, and/or distribute this software for any +dnl purpose with or without fee is hereby granted, provided that the above +dnl copyright notice and this permission notice appear in all copies. +dnl +dnl THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +dnl REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +dnl MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY +dnl SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +dnl ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +dnl IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +dnl +dnl SPDX-License-Identifier: ISC + +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. +AC_DEFUN([RRA_PROG_CC_FLAG], +[AC_REQUIRE([AC_PROG_CC]) + AC_MSG_CHECKING([if $CC supports $1]) + AC_CACHE_VAL([_RRA_PROG_CC_FLAG_CACHE([$1])], + [save_CFLAGS=$CFLAGS + AS_CASE([$1], + [-Wno-*], [CFLAGS="$CFLAGS `echo "$1" | sed 's/-Wno-/-W/'`"], + [*], [CFLAGS="$CFLAGS $1"]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [int foo = 0;])], + [_RRA_PROG_CC_FLAG_CACHE([$1])=yes], + [_RRA_PROG_CC_FLAG_CACHE([$1])=no]) + CFLAGS=$save_CFLAGS]) + AC_MSG_RESULT([$_RRA_PROG_CC_FLAG_CACHE([$1])]) + AS_IF([test x"$_RRA_PROG_CC_FLAG_CACHE([$1])" = xyes], [$2], [$3])]) + +dnl Determine the full set of viable warning flags for the current compiler. +dnl +dnl This is based partly on personal preference and is a fairly aggressive set +dnl of warnings. Desirable CC warnings that can't be turned on due to other +dnl problems: +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 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. +dnl +dnl For Clang, we try to use -Weverything, but we have to disable some of the +dnl warnings: +dnl +dnl -Wcast-qual Some structs require casting away const +dnl -Wdisabled-macro-expansion Triggers on libc (sigaction.sa_handler) +dnl -Wpadded Not an actual problem +dnl -Wreserved-id-macros Autoconf sets several of these normally +dnl -Wsign-conversion Too many fiddly changes for the benefit +dnl -Wtautological-pointer-compare False positives with for loops +dnl -Wundef Conflicts with Autoconf probe results +dnl -Wunreachable-code Happens with optional compilation +dnl -Wunreachable-code-return Other compilers get confused +dnl -Wunused-macros Often used on suppressed branches +dnl -Wused-but-marked-unused Happens a lot with conditional code +dnl +dnl Sets WARNINGS_CFLAGS as a substitution variable. +AC_DEFUN([RRA_PROG_CC_WARNINGS_FLAGS], +[AC_REQUIRE([RRA_PROG_CC_CLANG]) + AS_IF([test x"$CLANG" = xyes], + [WARNINGS_CFLAGS="-Werror" + m4_foreach_w([flag], + [-Weverything -Wno-cast-qual -Wno-disabled-macro-expansion -Wno-padded + -Wno-sign-conversion -Wno-reserved-id-macro + -Wno-tautological-pointer-compare -Wno-undef -Wno-unreachable-code + -Wno-unreachable-code-return -Wno-unused-macros + -Wno-used-but-marked-unused], + [RRA_PROG_CC_FLAG(flag, + [WARNINGS_CFLAGS="${WARNINGS_CFLAGS} flag"])])], + [WARNINGS_CFLAGS="-g -O2 -D_FORTIFY_SOURCE=2 -Werror" + m4_foreach_w([flag], + [-fstrict-overflow -fstrict-aliasing -Wall -Wextra -Wformat=2 + -Wformat-overflow=2 -Wformat-signedness -Wformat-truncation=2 + -Wnull-dereference -Winit-self -Wswitch-enum -Wstrict-overflow=5 + -Wmissing-format-attribute -Walloc-zero -Wduplicated-branches + -Wduplicated-cond -Wtrampolines -Wfloat-equal + -Wdeclaration-after-statement -Wshadow -Wpointer-arith + -Wbad-function-cast -Wcast-align -Wwrite-strings -Wconversion + -Wno-sign-conversion -Wdate-time -Wjump-misses-init -Wlogical-op + -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes + -Wmissing-declarations -Wnormalized=nfc -Wpacked -Wredundant-decls + -Wrestrict -Wnested-externs -Winline -Wvla], + [RRA_PROG_CC_FLAG(flag, + [WARNINGS_CFLAGS="${WARNINGS_CFLAGS} flag"])])]) + AC_SUBST([WARNINGS_CFLAGS])]) diff --git a/m4/clang.m4 b/m4/clang.m4 index 0659d82..c1815a5 100644 --- a/m4/clang.m4 +++ b/m4/clang.m4 @@ -3,13 +3,15 @@ dnl dnl If the current compiler is Clang, set the shell variable CLANG to yes. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Copyright 2015 Russ Allbery dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Source used by RRA_PROG_CC_CLANG. AC_DEFUN([_RRA_PROG_CC_CLANG_SOURCE], [[ diff --git a/m4/gssapi.m4 b/m4/gssapi.m4 index f2ad5bb..5828b1b 100644 --- a/m4/gssapi.m4 +++ b/m4/gssapi.m4 @@ -19,15 +19,17 @@ dnl Depends on RRA_KRB5_CONFIG, RRA_ENABLE_REDUCED_DEPENDS, and dnl RRA_SET_LDFLAGS. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2005, 2006, 2007, 2008, 2009, 2011, 2012 +dnl Copyright 2005-2009, 2011-2012 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Headers to include when probing for Kerberos library properties. AC_DEFUN([RRA_INCLUDES_GSSAPI], [[ diff --git a/m4/krb5-config.m4 b/m4/krb5-config.m4 index c69c4f3..bbfcdc1 100644 --- a/m4/krb5-config.m4 +++ b/m4/krb5-config.m4 @@ -8,15 +8,18 @@ dnl dnl Depends on RRA_ENABLE_REDUCED_DEPENDS. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2011, 2012 +dnl Copyright 2018 Russ Allbery +dnl Copyright 2011-2012 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Check for krb5-config in the user's path and set PATH_KRB5_CONFIG. This dnl is moved into a separate macro so that it can be loaded via AC_REQUIRE, @@ -75,12 +78,12 @@ dnl argument if that option was requested and not supported. Old versions of dnl krb5-config didn't take an argument to specify the library type, but dnl always returned the flags for libkrb5. AC_DEFUN([RRA_KRB5_CONFIG], -[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH]) - rra_krb5_config_$3= +[rra_krb5_config_$3= rra_krb5_config_$3[]_ok= AS_IF([test x"$1" != x && test -x "$1/bin/krb5-config"], [rra_krb5_config_$3="$1/bin/krb5-config"], - [rra_krb5_config_$3="$PATH_KRB5_CONFIG"]) + [_RRA_KRB5_CONFIG_PATH + rra_krb5_config_$3="$PATH_KRB5_CONFIG"]) AS_IF([test x"$rra_krb5_config_$3" != x && test -x "$rra_krb5_config_$3"], [AC_CACHE_CHECK([for $2 support in krb5-config], [rra_cv_lib_$3[]_config], [AS_IF(["$rra_krb5_config_$3" 2>&1 | grep $2 >/dev/null 2>&1], diff --git a/m4/krb5.m4 b/m4/krb5.m4 index 683e30b..8d9db43 100644 --- a/m4/krb5.m4 +++ b/m4/krb5.m4 @@ -47,15 +47,17 @@ dnl Also provides RRA_INCLUDES_KRB5, which are the headers to include when dnl probing the Kerberos library properties. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 +dnl Copyright 2005-2011, 2013-2014 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Ignore Automake conditionals if not using Automake. m4_define_default([AM_CONDITIONAL], [:]) diff --git a/m4/lib-depends.m4 b/m4/lib-depends.m4 index 22d38ee..09a2cf9 100644 --- a/m4/lib-depends.m4 +++ b/m4/lib-depends.m4 @@ -10,15 +10,17 @@ dnl This macro doesn't do much but is defined separately so that other macros dnl can require it with AC_REQUIRE. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2005, 2006, 2007 +dnl Copyright 2005-2007 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR AC_DEFUN([RRA_ENABLE_REDUCED_DEPENDS], [rra_reduced_depends=false diff --git a/m4/lib-pathname.m4 b/m4/lib-pathname.m4 index 828270f..46e8879 100644 --- a/m4/lib-pathname.m4 +++ b/m4/lib-pathname.m4 @@ -13,15 +13,17 @@ dnl This file also provides the Autoconf macro RRA_SET_LIBDIR, which sets the dnl libdir variable to PREFIX/lib{,32,64} as appropriate. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2008, 2009 +dnl Copyright 2008-2009 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Probe for the alternate library name that we should attempt on this dnl architecture, given the size of an int, and set rra_lib_arch_name to that diff --git a/m4/remctl.m4 b/m4/remctl.m4 index c2fbf9a..292313f 100644 --- a/m4/remctl.m4 +++ b/m4/remctl.m4 @@ -23,15 +23,17 @@ dnl Depends on RRA_ENABLE_REDUCED_DEPENDS, RRA_SET_LDFLAGS, and dnl RRA_LIB_GSSAPI. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2008, 2009, 2011, 2013 +dnl Copyright 2008-2009, 2011, 2013 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to dnl versions that include the remctl flags. Used as a wrapper, with diff --git a/m4/snprintf.m4 b/m4/snprintf.m4 index f134ab9..e739bbf 100644 --- a/m4/snprintf.m4 +++ b/m4/snprintf.m4 @@ -10,15 +10,17 @@ dnl Provides RRA_FUNC_SNPRINTF, which adds snprintf.o to LIBOBJS unless a dnl fully working snprintf is found. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2006, 2008, 2009 +dnl Copyright 2006, 2008-2009 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR dnl Source used by RRA_FUNC_SNPRINTF. AC_DEFUN([_RRA_FUNC_SNPRINTF_SOURCE], [[ diff --git a/m4/vamacros.m4 b/m4/vamacros.m4 index 62fb82d..5595b86 100644 --- a/m4/vamacros.m4 +++ b/m4/vamacros.m4 @@ -14,15 +14,17 @@ dnl dnl They set HAVE_C99_VAMACROS or HAVE_GNU_VAMACROS as appropriate. dnl dnl The canonical version of this file is maintained in the rra-c-util -dnl package, available at . +dnl package, available at . dnl dnl Written by Russ Allbery -dnl Copyright 2006, 2008, 2009 +dnl Copyright 2006, 2008-2009 dnl The Board of Trustees of the Leland Stanford Junior University dnl dnl This file is free software; the authors give unlimited permission to copy dnl and/or distribute it, with or without modifications, as long as this dnl notice is preserved. +dnl +dnl SPDX-License-Identifier: FSFULLR AC_DEFUN([_RRA_C_C99_VAMACROS_SOURCE], [[ #include diff --git a/perl/t/docs/pod-spelling.t b/perl/t/docs/pod-spelling.t index 6debd42..94d7503 100755 --- a/perl/t/docs/pod-spelling.t +++ b/perl/t/docs/pod-spelling.t @@ -3,10 +3,10 @@ # Check for spelling errors in POD documentation. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2013, 2014 +# Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; diff --git a/perl/t/docs/pod.t b/perl/t/docs/pod.t index 674ce30..5fcfcdf 100755 --- a/perl/t/docs/pod.t +++ b/perl/t/docs/pod.t @@ -3,10 +3,10 @@ # Check all POD documents for POD formatting errors. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2012, 2013, 2014 +# Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; diff --git a/perl/t/style/minimum-version.t b/perl/t/style/minimum-version.t index e4eeafd..7698c2b 100755 --- a/perl/t/style/minimum-version.t +++ b/perl/t/style/minimum-version.t @@ -3,10 +3,10 @@ # Check that too-new features of Perl are not being used. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2013, 2014 +# Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; diff --git a/perl/t/style/strict.t b/perl/t/style/strict.t index 7137b15..a3d2a3e 100755 --- a/perl/t/style/strict.t +++ b/perl/t/style/strict.t @@ -3,10 +3,11 @@ # Test Perl code for strict, warnings, and syntax. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2013, 2014 +# Copyright 2016 Russ Allbery +# Copyright 2013-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +27,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; @@ -39,8 +42,9 @@ use Test::RRA qw(skip_unless_automated use_prereq); # Skip for normal user installs since this doesn't affect functionality. skip_unless_automated('Strictness tests'); -# Load prerequisite modules. -use_prereq('Test::Strict'); +# Load prerequisite modules. At least 0.25 is needed to recognize that having +# 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 diff --git a/portable/asprintf.c b/portable/asprintf.c index 9693842..aef3639 100644 --- a/portable/asprintf.c +++ b/portable/asprintf.c @@ -5,17 +5,19 @@ * asprintf and vasprintf for those platforms that don't have them. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2006, 2015 Russ Allbery + * Copyright 2008-2009, 2011, 2013 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include diff --git a/portable/dummy.c b/portable/dummy.c index 890bc0c..121a734 100644 --- a/portable/dummy.c +++ b/portable/dummy.c @@ -6,23 +6,25 @@ * arguments. Ensure that libportable always contains at least one symbol. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2017 Russ Allbery + * Copyright 2008, 2011, 2013 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include /* Prototype to avoid gcc warnings and set visibility. */ -int portable_dummy(void) __attribute__((__visibility__("hidden"))); +int portable_dummy(void) __attribute__((__const__, __visibility__("hidden"))); int portable_dummy(void) diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c index c8309a4..9de8e65 100644 --- a/portable/krb5-extra.c +++ b/portable/krb5-extra.c @@ -7,17 +7,19 @@ * Kerberos libraries are fully capable, this file will be skipped. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2015-2016, 2018 Russ Allbery + * Copyright 2010-2012, 2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include @@ -49,7 +51,10 @@ * This string is returned for unknown error messages. We use a static * variable so that we can be sure not to free it. */ +#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) \ + || !defined(HAVE_KRB5_FREE_ERROR_MESSAGE) static const char error_unknown[] = "unknown error"; +#endif #ifndef HAVE_KRB5_GET_ERROR_MESSAGE @@ -62,7 +67,7 @@ static const char error_unknown[] = "unknown error"; const char * krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED) { - const char *msg = NULL; + const char *msg; # if defined(HAVE_KRB5_GET_ERROR_STRING) msg = krb5_get_error_string(ctx); diff --git a/portable/krb5-profile.c b/portable/krb5-profile.c new file mode 100644 index 0000000..f4d4652 --- /dev/null +++ b/portable/krb5-profile.c @@ -0,0 +1,237 @@ +/* + * Kerberos compatibility functions for AIX's NAS libraries. + * + * AIX for some reason doesn't provide the krb5_appdefault_* functions, but + * does provide the underlying profile library functions (as a separate + * libk5profile with a separate k5profile.h header file). + * + * This file is therefore (apart from the includes, opening and closing + * comments, and the spots marked with an rra-c-util comment) a verbatim copy + * of src/lib/krb5/krb/appdefault.c from MIT Kerberos 1.4.4. + * + * The canonical version of this file is maintained in the rra-c-util package, + * which can be found at . + * + * Copyright 1985-2005 by the Massachusetts Institute of Technology. + * For license information, see the end of this file. + */ + +#include + +#include +#ifdef HAVE_K5PROFILE_H +# include +#endif +#ifdef HAVE_PROFILE_H +# include +#endif +#include +#include + + /*xxx Duplicating this is annoying; try to work on a better way.*/ +static const char *const conf_yes[] = { + "y", "yes", "true", "t", "1", "on", + 0, +}; + +static const char *const conf_no[] = { + "n", "no", "false", "nil", "0", "off", + 0, +}; + +static int conf_boolean(char *s) +{ + const char * const *p; + for(p=conf_yes; *p; p++) { + if (!strcasecmp(*p,s)) + return 1; + } + for(p=conf_no; *p; p++) { + if (!strcasecmp(*p,s)) + return 0; + } + /* Default to "no" */ + return 0; +} + +static krb5_error_code appdefault_get(krb5_context context, const char *appname, const krb5_data *realm, const char *option, char **ret_value) +{ + profile_t profile; + const char *names[5]; + char **nameval = NULL; + krb5_error_code retval; + const char * realmstr = realm?realm->data:NULL; + + /* + * rra-c-util: The magic values are internal, so a magic check for the + * context struct was removed here. Call krb5_get_profile if it's + * available since the krb5_context struct may be opaque. + */ + if (!context) + return KV5M_CONTEXT; + +#ifdef HAVE_KRB5_GET_PROFILE + krb5_get_profile(context, &profile); +#else + profile = context->profile; +#endif + + /* + * Try number one: + * + * [appdefaults] + * app = { + * SOME.REALM = { + * option = + * } + * } + */ + + names[0] = "appdefaults"; + names[1] = appname; + + if (realmstr) { + names[2] = realmstr; + names[3] = option; + names[4] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + } + + /* + * Try number two: + * + * [appdefaults] + * app = { + * option = + * } + */ + + names[2] = option; + names[3] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + + /* + * Try number three: + * + * [appdefaults] + * realm = { + * option = + */ + + if (realmstr) { + names[1] = realmstr; + names[2] = option; + names[3] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + } + + /* + * Try number four: + * + * [appdefaults] + * option = + */ + + names[1] = option; + names[2] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + } else { + return retval; + } + +goodbye: + if (nameval) { + char **cpp; + for (cpp = nameval; *cpp; cpp++) + free(*cpp); + free(nameval); + } + return 0; +} + +void KRB5_CALLCONV +krb5_appdefault_boolean(krb5_context context, const char *appname, const krb5_data *realm, const char *option, int default_value, int *ret_value) +{ + char *string = NULL; + krb5_error_code retval; + + retval = appdefault_get(context, appname, realm, option, &string); + + if (! retval && string) { + *ret_value = conf_boolean(string); + free(string); + } else + *ret_value = default_value; +} + +void KRB5_CALLCONV +krb5_appdefault_string(krb5_context context, const char *appname, const krb5_data *realm, const char *option, const char *default_value, char **ret_value) +{ + krb5_error_code retval; + char *string; + + retval = appdefault_get(context, appname, realm, option, &string); + + if (! retval && string) { + *ret_value = string; + } else { + *ret_value = strdup(default_value); + } +} + +/* + * Copyright (C) 1985-2005 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may require + * a specific license from the United States Government. It is the + * responsibility of any person or organization contemplating export to + * obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original MIT software. + * M.I.T. makes no representations about the suitability of this software + * for any purpose. It is provided "as is" without express or implied + * warranty. + * + * 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. + * + * Individual source code files are copyright MIT, Cygnus Support, + * OpenVision, Oracle, Sun Soft, FundsXpress, and others. + * + * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, + * and Zephyr are trademarks of the Massachusetts Institute of Technology + * (MIT). No commercial use of these trademarks may be made without + * prior written permission of MIT. + * + * "Commercial use" means use of a name in a product or other for-profit + * manner. It does NOT prevent a commercial firm from referring to the + * MIT trademarks in order to convey information (although in doing so, + * recognition of their trademark status should be given). + * + * There is no SPDX-License-Identifier registered for this license. + */ diff --git a/portable/krb5.h b/portable/krb5.h index 34f960e..63a2e9f 100644 --- a/portable/krb5.h +++ b/portable/krb5.h @@ -17,17 +17,19 @@ * krb5_free_unparsed_name() for both APIs since it's the most specific call. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2015, 2017 Russ Allbery + * Copyright 2010-2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef PORTABLE_KRB5_H @@ -56,6 +58,18 @@ BEGIN_DECLS /* Default to a hidden visibility for all portability functions. */ #pragma GCC visibility push(hidden) +/* + * AIX included Kerberos includes the profile library but not the + * krb5_appdefault functions, so we provide replacements that we have to + * prototype. + */ +#ifndef HAVE_KRB5_APPDEFAULT_STRING +void krb5_appdefault_boolean(krb5_context, const char *, const krb5_data *, + const char *, int, int *); +void krb5_appdefault_string(krb5_context, const char *, const krb5_data *, + const char *, const char *, char **); +#endif + /* * krb5_{get,free}_error_message are the preferred APIs for both current MIT * and current Heimdal, but there are tons of older APIs we may have to fall diff --git a/portable/macros.h b/portable/macros.h index d4cc2cc..586b07e 100644 --- a/portable/macros.h +++ b/portable/macros.h @@ -2,17 +2,19 @@ * Portability macros used in include files. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2015 Russ Allbery + * Copyright 2008, 2011-2012 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef PORTABLE_MACROS_H diff --git a/portable/mkstemp.c b/portable/mkstemp.c index 7c733a4..9e3bba1 100644 --- a/portable/mkstemp.c +++ b/portable/mkstemp.c @@ -5,17 +5,18 @@ * systems that don't have it. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2009, 2011, 2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include diff --git a/portable/reallocarray.c b/portable/reallocarray.c index e9404e9..3c6ea37 100644 --- a/portable/reallocarray.c +++ b/portable/reallocarray.c @@ -7,17 +7,19 @@ * and checks for overflow so that the caller doesn't need to. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2017 Russ Allbery + * Copyright 2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include @@ -52,5 +54,11 @@ reallocarray(void *ptr, size_t nmemb, size_t size) errno = ENOMEM; return NULL; } + + /* Avoid a zero-size allocation. */ + if (nmemb == 0 || size == 0) { + nmemb = 1; + size = 1; + } return realloc(ptr, nmemb * size); } diff --git a/portable/setenv.c b/portable/setenv.c index f1f6db4..afa8930 100644 --- a/portable/setenv.c +++ b/portable/setenv.c @@ -5,17 +5,19 @@ * those platforms that don't have it. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2000, 2014 Russ Allbery + * Copyright 2008, 2011-2012, 2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include diff --git a/portable/snprintf.c b/portable/snprintf.c index 9818acd..a42ef3b 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -11,7 +11,7 @@ * improvements should be sent back to the original author. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . */ /* @@ -25,11 +25,18 @@ # define vsnprintf test_vsnprintf #endif +/* Specific to rra-c-util, but only when debugging is enabled. */ +#ifdef DEBUG_SNPRINTF +# include +#endif + /* * Copyright Patrick Powell 1995 * This code is based on code written by Patrick Powell (papowell@astart.com) * It may be used for any purpose as long as this notice remains intact * on all source code distributions + * + * There is no SPDX-License-Identifier registered for this license. */ /************************************************************** @@ -79,11 +86,24 @@ * Russ Allbery 2000-08-26 * fixed return value to comply with C99 * fixed handling of snprintf(NULL, ...) + * added explicit casts for double to long long int conversion + * fixed various warnings with GCC 7 + * fixed various warnings with Clang * - * Hrvoje Niksic 2000-11-04 + * Hrvoje Niksic 2000-11-04 + * include instead of "config.h". + * moved TEST_SNPRINTF stuff out of HAVE_SNPRINTF ifdef. * include for NULL. - * added support for long long. + * added support and test cases for long long. * don't declare argument types to (v)snprintf if stdarg is not used. + * use int instead of short int as 2nd arg to va_arg. + * + * alexk (INN) 2002-08-21 + * use LLONG in fmtfp to handle more characters during floating + * point conversion. + * + * herb (Samba) 2002-12-19 + * actually print args for %g and %e * * Hrvoje Niksic 2005-04-15 * use the PARAMS macro to handle prototypes. @@ -109,11 +129,6 @@ /* varargs declarations: */ #include -#define HAVE_STDARGS /* let's hope that works everywhere (mj) */ -#define VA_LOCAL_DECL va_list ap -#define VA_START(f) va_start(ap, f) -#define VA_SHIFT(v,t) ; /* no-op for ANSI */ -#define VA_END va_end(ap) /* Assume all compilers support long double, per Autoconf documentation. */ #define LDOUBLE long double @@ -180,7 +195,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) char *strvalue; int min; int max; - int state; + unsigned int state; int flags; int cflags; int total; @@ -351,6 +366,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'X': flags |= DP_F_UP; + /* fallthrough */ case 'x': flags |= DP_F_UNSIGNED; if (cflags == DP_C_SHORT) @@ -367,33 +383,36 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); else - fvalue = va_arg (args, double); + fvalue = (LDOUBLE) va_arg (args, double); total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); break; case 'E': flags |= DP_F_UP; + /* fallthrough */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); else - fvalue = va_arg (args, double); + fvalue = (LDOUBLE) va_arg (args, double); total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); break; case 'G': flags |= DP_F_UP; + /* fallthrough */ case 'g': flags |= DP_F_FP_G; if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); else - fvalue = va_arg (args, double); + fvalue = (LDOUBLE) va_arg (args, double); if (max == 0) /* C99 says: if precision [for %g] is zero, it is taken as one */ max = 1; total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); break; case 'c': - total += dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); + total += dopr_outch (buffer, &currlen, maxlen, + (char) va_arg (args, int)); break; case 's': strvalue = va_arg (args, char *); @@ -409,7 +428,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) { short int *num; num = va_arg (args, short int *); - *num = currlen; + *num = (short) currlen; } else if (cflags == DP_C_LONG) { @@ -427,7 +446,7 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) { int *num; num = va_arg (args, int *); - *num = currlen; + *num = (int) currlen; } break; case '%': @@ -476,7 +495,7 @@ static int fmtstr (char *buffer, size_t *currlen, size_t maxlen, } if (max < 0) - strln = strlen (value); + strln = (int) strlen (value); else /* When precision is specified, don't read VALUE past precision. */ /*strln = strnlen (value, max);*/ @@ -510,7 +529,7 @@ static int fmtstr (char *buffer, size_t *currlen, size_t maxlen, static int fmtint (char *buffer, size_t *currlen, size_t maxlen, LLONG value, int base, int min, int max, int flags) { - int signvalue = 0; + char signvalue = 0; unsigned LLONG uvalue; char convert[24]; unsigned int place = 0; @@ -564,8 +583,8 @@ static int fmtint (char *buffer, size_t *currlen, size_t maxlen, spadlen = -spadlen; /* Left Justifty */ #ifdef DEBUG_SNPRINTF - dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", - zpadlen, spadlen, min, max, place)); + debug ("zpad: %d, spad: %d, min: %d, max: %d, place: %u\n", + zpadlen, spadlen, min, max, place); #endif /* Spaces */ @@ -612,7 +631,7 @@ static LDOUBLE abs_val (LDOUBLE value) return result; } -static LDOUBLE pow10_int (int exp) +static LLONG pow10_int (unsigned int exp) { LDOUBLE result = 1; @@ -622,32 +641,40 @@ static LDOUBLE pow10_int (int exp) exp--; } - return result; + return (LLONG) result; } static LLONG round_int (LDOUBLE value) { LLONG intpart; - intpart = value; + intpart = (LLONG) value; value = value - intpart; - if (value >= 0.5) + if (value >= (LDOUBLE) 0.5) intpart++; return intpart; } +/* + * GCC 7.1 issues this warning at the point of the function definition header + * (not in any actual code), and I can't figure out what's triggering it since + * the comparison form doesn't appear anywhere in this code. Since this is + * rarely-used portability code, suppress the warning. + */ +#pragma GCC diagnostic ignored "-Wstrict-overflow" + static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, LDOUBLE fvalue, int min, int max, int flags) { - int signvalue = 0; + char signvalue = 0; LDOUBLE ufvalue; char iconvert[24]; char fconvert[24]; size_t iplace = 0; size_t fplace = 0; - int padlen = 0; /* amount to pad */ - int zpadlen = 0; + long padlen = 0; /* amount to pad */ + long zpadlen = 0; int total = 0; LLONG intpart; LLONG fracpart; @@ -678,7 +705,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ #endif - intpart = ufvalue; + intpart = (LLONG) ufvalue; /* With %g precision is the number of significant digits, which includes the digits in intpart. */ @@ -699,7 +726,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, fractional digit. */ LDOUBLE temp; if (ufvalue > 0) - for (temp = ufvalue; temp < 0.1; temp *= 10) + for (temp = ufvalue; temp < (LDOUBLE) 0.1; temp *= 10) ++max; } } @@ -746,12 +773,16 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, } #ifdef DEBUG_SNPRINTF - dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart)); +# ifdef HAVE_LONG_LONG_INT + debug ("fmtfp: %Lf =? %lld.%lld\n", fvalue, intpart, fracpart); +# else + debug ("fmtfp: %Lf =? %ld.%ld\n", fvalue, intpart, fracpart); +# endif #endif /* Convert integer part */ do { - iconvert[iplace++] = '0' + intpart % 10; + iconvert[iplace++] = (char) ('0' + (intpart % 10)); intpart = (intpart / 10); } while(intpart && (iplace < sizeof(iconvert))); if (iplace == sizeof(iconvert)) iplace--; @@ -759,7 +790,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, /* Convert fractional part */ do { - fconvert[fplace++] = '0' + fracpart % 10; + fconvert[fplace++] = (char) ('0' + (fracpart % 10)); fracpart = (fracpart / 10); } while(fracpart && (fplace < sizeof(fconvert))); while (leadingfrac0s-- > 0 && fplace < sizeof(fconvert)) @@ -847,27 +878,14 @@ int vsnprintf (char *str, size_t count, const char *fmt, va_list args) return dopr(str, count, fmt, args); } -/* VARARGS3 */ -#ifdef HAVE_STDARGS -int snprintf (char *str,size_t count,const char *fmt,...) -#else -int snprintf (va_alist) va_dcl -#endif +int snprintf (char *str, size_t count, const char *fmt,...) { -#ifndef HAVE_STDARGS - char *str; - size_t count; - char *fmt; -#endif - VA_LOCAL_DECL; + va_list ap; int total; - VA_START (fmt); - VA_SHIFT (str, char *); - VA_SHIFT (count, size_t ); - VA_SHIFT (fmt, char *); + va_start(ap, fmt); total = vsnprintf(str, count, fmt, ap); - VA_END; + va_end(ap); return total; } @@ -944,5 +962,6 @@ int main (void) num++; } printf ("%d tests failed out of %d.\n", fail, num); + return 0; } -#endif /* SNPRINTF_TEST */ +#endif /* TEST_SNPRINTF */ diff --git a/portable/stdbool.h b/portable/stdbool.h index 14d011b..3efe4c9 100644 --- a/portable/stdbool.h +++ b/portable/stdbool.h @@ -6,17 +6,18 @@ * logic is based heavily on the example in the Autoconf manual. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2008, 2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef PORTABLE_STDBOOL_H diff --git a/portable/system.h b/portable/system.h index f683300..6fe4928 100644 --- a/portable/system.h +++ b/portable/system.h @@ -22,17 +22,19 @@ * the portable helper library. Also provides some standard #defines. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2014, 2016, 2018 Russ Allbery + * Copyright 2006-2011, 2013-2014 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef PORTABLE_SYSTEM_H @@ -73,6 +75,11 @@ /* Get the bool type. */ #include +/* In case uint32_t and associated limits weren't defined. */ +#ifndef UINT32_MAX +# define UINT32_MAX 4294967295UL +#endif + /* Windows provides snprintf under a different name. */ #ifdef _WIN32 # define snprintf _snprintf @@ -118,14 +125,16 @@ BEGIN_DECLS #if !HAVE_ASPRINTF extern int asprintf(char **, const char *, ...) __attribute__((__format__(printf, 2, 3))); -extern int vasprintf(char **, const char *, va_list); +extern int vasprintf(char **, const char *, va_list) + __attribute__((__format__(printf, 2, 0))); #endif #if !HAVE_DECL_SNPRINTF extern int snprintf(char *, size_t, const char *, ...) __attribute__((__format__(printf, 3, 4))); #endif #if !HAVE_DECL_VSNPRINTF -extern int vsnprintf(char *, size_t, const char *, va_list); +extern int vsnprintf(char *, size_t, const char *, va_list) + __attribute__((__format__(printf, 3, 0))); #endif #if !HAVE_MKSTEMP extern int mkstemp(char *); diff --git a/portable/uio.h b/portable/uio.h index 2192f8c..8635d18 100644 --- a/portable/uio.h +++ b/portable/uio.h @@ -6,17 +6,18 @@ * functions are not provided or prototyped here. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2008, 2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef PORTABLE_UIO_H diff --git a/tests/HOWTO b/tests/HOWTO deleted file mode 100644 index b94985d..0000000 --- a/tests/HOWTO +++ /dev/null @@ -1,248 +0,0 @@ - Writing TAP Tests - -Introduction - - This is a guide for users of the C TAP Harness package or similar - TAP-based test harnesses explaining how to write tests. If your - package uses C TAP Harness as the test suite driver, you may want to - copy this document to an appropriate file name in your test suite as - documentation for contributors. - -About TAP - - TAP is the Test Anything Protocol, a protocol for communication - between test cases and a test harness. This is the protocol used by - Perl for its internal test suite and for nearly all Perl modules, - since it's the format used by the build tools for Perl modules to run - tests and report their results. - - A TAP-based test suite works with a somewhat different set of - assumptions than an xUnit test suite. In TAP, each test case is a - separate program. That program, when run, must produce output in the - following format: - - 1..4 - ok 1 - the first test - ok 2 - # a diagnostic, ignored by the harness - not ok 3 - a failing test - ok 4 # skip a skipped test - - The output should all go to standard output. The first line specifies - the number of tests to be run, and then each test produces output that - looks like either "ok " or "not ok " depending on whether the - test succeeded or failed. Additional information about the test can - be provided after the "ok " or "not ok ", but is optional. - Additional diagnostics and information can be provided in lines - beginning with a "#". - - Processing directives are supported after the "ok " or "not ok " - and start with a "#". The main one of interest is "# skip" which says - that the test was skipped rather than successful and optionally gives - the reason. Also supported is "# todo", which normally annotates a - failing test and indicates that test is expected to fail, optionally - providing a reason for why. - - There are three more special cases. First, the initial line stating - the number of tests to run, called the plan, may appear at the end of - the output instead of the beginning. This can be useful if the number - of tests to run is not known in advance. Second, a plan in the form: - - 1..0 # skip entire test case skipped - - can be given instead, which indicates that this entire test case has - been skipped (generally because it depends on facilities or optional - configuration which is not present). Finally, if the test case - encounters a fatal error, it should print the text: - - Bail out! - - on standard output, optionally followed by an error message, and then - exit. This tells the harness that the test aborted unexpectedly. - - The exit status of a successful test case should always be 0. The - harness will report the test as "dubious" if all the tests appeared to - succeed but it exited with a non-zero status. - -Writing TAP Tests - - Environment - - One of the special features of C TAP Harness is the environment that - it sets up for your test cases. If your test program is called under - the runtests driver, the environment variables SOURCE and BUILD will - be set to the top of the test directory in the source tree and the top - of the build tree, respectively. You can use those environment - variables to locate additional test data, programs and libraries built - as part of your software build, and other supporting information - needed by tests. - - The C and shell TAP libraries support a test_file_path() function, - which looks for a file under the build tree and then under the source - tree, using the BUILD and SOURCE environment variables, and return the - full path to the file. This can be used to locate supporting data - files. - - Perl - - Since TAP is the native test framework for Perl, writing TAP tests in - Perl is very easy and extremely well-supported. If you've never - written tests in Perl before, start by reading the documentation for - Test::Tutorial and Test::Simple, which walks you through the basics, - including the TAP output syntax. Then, the best Perl module to use - for serious testing is Test::More, which provides a lot of additional - functions over Test::Simple including support for skipping tests, - bailing out, and not planning tests in advance. See the documentation - of Test::More for all the details and lots of examples. - - C TAP Harness can run Perl test scripts directly and interpret the - results correctly, and similarly the Perl Test::Harness module and - prove command can run TAP tests written in other languages using, for - example, the TAP library that comes with C TAP Harness. You can, if - you wish, use the library that comes with C TAP Harness but use prove - instead of runtests for running the test suite. - - C - - C TAP Harness provides a basic TAP library that takes away most of the - pain of writing TAP test cases in C. A C test case should start with - a call to plan(), passing in the number of tests to run. Then, each - test should use is_int(), is_string(), is_double(), or is_hex() as - appropriate to compare expected and seen values, or ok() to do a - simpler boolean test. The is_*() functions take expected and seen - values and then a printf-style format string explaining the test - (which may be NULL). ok() takes a boolean and then the printf-style - string. - - Here's a complete example test program that uses the C TAP library: - - #include - #include - - int - main(void) - { - plan(4); - - ok(1, "the first test"); - is_int(42, 42, NULL); - diag("a diagnostic, ignored by the harness"); - ok(0, "a failing test"); - skip("a skipped test"); - - return 0; - } - - This test program produces the output shown above in the section on - TAP and demonstrates most of the functions. The other functions of - interest are sysdiag() (like diag() but adds strerror() results), - bail() and sysbail() for fatal errors, skip_block() to skip a whole - block of tests, and skip_all() which is called instead of plan() to - skip an entire test case. - - The C TAP library also provides plan_lazy(), which can be called - instead of plan(). If plan_lazy() is called, the library will keep - track of how many test results are reported and will print out the - plan at the end of execution of the program. This should normally be - avoided since the test may appear to be successful even if it exits - prematurely, but it can make writing tests easier in some - circumstances. - - Complete API documentation for the basic C TAP library that comes with - C TAP Harness is available at: - - - - It's common to need additional test functions and utility functions - for your C tests, particularly if you have to set up and tear down a - test environment for your test programs, and it's useful to have them - all in the libtap library so that you only have to link your test - programs with one library. Rather than editing tap/basic.c and - tap/basic.h to add those additional functions, add additional *.c and - *.h files into the tap directory with the function implementations and - prototypes, and then add those additional objects to the library. - That way, you can update tap/basic.c and tap/basic.h from subsequent - releases of C TAP Harness without having to merge changes with your - own code. - - Libraries of additional useful TAP test functions are available in - rra-c-util at: - - - - Some of the code there is particularly useful when testing programs - that require Kerberos keys. - - If you implement new test functions that compare an expected and seen - value, it's best to name them is_ and take the expected - value, the seen value, and then a printf-style format string and - possible arguments to match the calling convention of the functions - provided by C TAP Harness. - - Shell - - C TAP Harness provides a library of shell functions to make it easier - to write TAP tests in shell. That library includes much of the same - functionality as the C TAP library, but takes its parameters in a - somewhat different order to make better use of shell features. - - The libtap.sh file should be installed in a directory named tap in - your test suite area. It can then be loaded by tests written in shell - using the environment set up by runtests with: - - . "$SOURCE"/tap/libtap.sh - - Here is a complete test case written in shell which produces the same - output as the TAP sample above: - - #!/bin/sh - - . "$SOURCE"/tap/libtap.sh - cd "$BUILD" - - plan 4 - ok 'the first test' true - ok '' [ 42 -eq 42 ] - diag a diagnostic, ignored by the harness - ok '' false - skip 'a skipped test' - - The shell framework doesn't provide the is_* functions, so you'll use - the ok function more. It takes a string describing the text and then - treats all of its remaining arguments as a condition, evaluated the - same way as the arguments to the "if" statement. If that condition - evaluates to true, the test passes; otherwise, the test fails. - - The plan, plan_lazy, diag, and bail functions work the same as with - the C library. skip takes a string and skips the next test with that - explanation. skip_block takes a count and a string and skips that - many tests with that explanation. skip_all takes an optional reason - and skips the entire test case. - - Since it's common for shell programs to want to test the output of - commands, there's an additional function ok_program provided by the - shell test library. It takes the test description string, the - expected exit status, the expected program output, and then treats the - rest of its arguments as the program to run. That program is run with - standard error and standard output combined, and then its exit status - and output are tested against the provided values. - - A utility function, strip_colon_error, is provided that runs the - command given as its arguments and strips text following a colon and a - space from the output (unless there is no whitespace on the line - before the colon and the space, normally indicating a prefix of the - program name). This function can be used to wrap commands that are - expected to fail with output that has a system- or locale-specific - error message appended, such as the output of strerror(). - -License - - This file is part of the documentation of C TAP Harness, which can be - found at . - - Copyright 2010 Russ Allbery - - Copying and distribution of this file, with or without modification, - are permitted in any medium without royalty provided the copyright - notice and this notice are preserved. This file is offered as-is, - without any warranty. diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..186d2d5 --- /dev/null +++ b/tests/README @@ -0,0 +1,252 @@ + Writing TAP Tests + +Introduction + + This is a guide for users of the C TAP Harness package or similar + TAP-based test harnesses explaining how to write tests. If your + package uses C TAP Harness as the test suite driver, you may want to + copy this document to an appropriate file name in your test suite as + documentation for contributors. + +About TAP + + TAP is the Test Anything Protocol, a protocol for communication + between test cases and a test harness. This is the protocol used by + Perl for its internal test suite and for nearly all Perl modules, + since it's the format used by the build tools for Perl modules to run + tests and report their results. + + A TAP-based test suite works with a somewhat different set of + assumptions than an xUnit test suite. In TAP, each test case is a + separate program. That program, when run, must produce output in the + following format: + + 1..4 + ok 1 - the first test + ok 2 + # a diagnostic, ignored by the harness + not ok 3 - a failing test + ok 4 # skip a skipped test + + The output should all go to standard output. The first line specifies + the number of tests to be run, and then each test produces output that + looks like either "ok " or "not ok " depending on whether the + test succeeded or failed. Additional information about the test can + be provided after the "ok " or "not ok ", but is optional. + Additional diagnostics and information can be provided in lines + beginning with a "#". + + Processing directives are supported after the "ok " or "not ok " + and start with a "#". The main one of interest is "# skip" which says + that the test was skipped rather than successful and optionally gives + the reason. Also supported is "# todo", which normally annotates a + failing test and indicates that test is expected to fail, optionally + providing a reason for why. + + There are three more special cases. First, the initial line stating + the number of tests to run, called the plan, may appear at the end of + the output instead of the beginning. This can be useful if the number + of tests to run is not known in advance. Second, a plan in the form: + + 1..0 # skip entire test case skipped + + can be given instead, which indicates that this entire test case has + been skipped (generally because it depends on facilities or optional + configuration which is not present). Finally, if the test case + encounters a fatal error, it should print the text: + + Bail out! + + on standard output, optionally followed by an error message, and then + exit. This tells the harness that the test aborted unexpectedly. + + The exit status of a successful test case should always be 0. The + harness will report the test as "dubious" if all the tests appeared to + succeed but it exited with a non-zero status. + +Writing TAP Tests + + Environment + + One of the special features of C TAP Harness is the environment that + it sets up for your test cases. If your test program is called under + the runtests driver, the environment variables C_TAP_SOURCE and + C_TAP_BUILD will be set to the top of the test directory in the source + tree and the top of the build tree, respectively. You can use those + environment variables to locate additional test data, programs and + libraries built as part of your software build, and other supporting + information needed by tests. + + The C and shell TAP libraries support a test_file_path() function, + which looks for a file under the build tree and then under the source + tree, using the C_TAP_BUILD and C_TAP_SOURCE environment variables, + and return the full path to the file. This can be used to locate + supporting data files. They also support a test_tmpdir() function + that returns a directory that can be used for temporary files during + tests. + + Perl + + Since TAP is the native test framework for Perl, writing TAP tests in + Perl is very easy and extremely well-supported. If you've never + written tests in Perl before, start by reading the documentation for + Test::Tutorial and Test::Simple, which walks you through the basics, + including the TAP output syntax. Then, the best Perl module to use + for serious testing is Test::More, which provides a lot of additional + functions over Test::Simple including support for skipping tests, + bailing out, and not planning tests in advance. See the documentation + of Test::More for all the details and lots of examples. + + C TAP Harness can run Perl test scripts directly and interpret the + results correctly, and similarly the Perl Test::Harness module and + prove command can run TAP tests written in other languages using, for + example, the TAP library that comes with C TAP Harness. You can, if + you wish, use the library that comes with C TAP Harness but use prove + instead of runtests for running the test suite. + + C + + C TAP Harness provides a basic TAP library that takes away most of the + pain of writing TAP test cases in C. A C test case should start with + a call to plan(), passing in the number of tests to run. Then, each + test should use is_int(), is_string(), is_double(), or is_hex() as + appropriate to compare expected and seen values, or ok() to do a + simpler boolean test. The is_*() functions take expected and seen + values and then a printf-style format string explaining the test + (which may be NULL). ok() takes a boolean and then the printf-style + string. + + Here's a complete example test program that uses the C TAP library: + + #include + #include + + int + main(void) + { + plan(4); + + ok(1, "the first test"); + is_int(42, 42, NULL); + diag("a diagnostic, ignored by the harness"); + ok(0, "a failing test"); + skip("a skipped test"); + + return 0; + } + + This test program produces the output shown above in the section on + TAP and demonstrates most of the functions. The other functions of + interest are sysdiag() (like diag() but adds strerror() results), + bail() and sysbail() for fatal errors, skip_block() to skip a whole + block of tests, and skip_all() which is called instead of plan() to + skip an entire test case. + + The C TAP library also provides plan_lazy(), which can be called + instead of plan(). If plan_lazy() is called, the library will keep + track of how many test results are reported and will print out the + plan at the end of execution of the program. This should normally be + avoided since the test may appear to be successful even if it exits + prematurely, but it can make writing tests easier in some + circumstances. + + Complete API documentation for the basic C TAP library that comes with + C TAP Harness is available at: + + + + It's common to need additional test functions and utility functions + for your C tests, particularly if you have to set up and tear down a + test environment for your test programs, and it's useful to have them + all in the libtap library so that you only have to link your test + programs with one library. Rather than editing tap/basic.c and + tap/basic.h to add those additional functions, add additional *.c and + *.h files into the tap directory with the function implementations and + prototypes, and then add those additional objects to the library. + That way, you can update tap/basic.c and tap/basic.h from subsequent + releases of C TAP Harness without having to merge changes with your + own code. + + Libraries of additional useful TAP test functions are available in + rra-c-util at: + + + + Some of the code there is particularly useful when testing programs + that require Kerberos keys. + + If you implement new test functions that compare an expected and seen + value, it's best to name them is_ and take the expected + value, the seen value, and then a printf-style format string and + possible arguments to match the calling convention of the functions + provided by C TAP Harness. + + Shell + + C TAP Harness provides a library of shell functions to make it easier + to write TAP tests in shell. That library includes much of the same + functionality as the C TAP library, but takes its parameters in a + somewhat different order to make better use of shell features. + + The libtap.sh file should be installed in a directory named tap in + your test suite area. It can then be loaded by tests written in shell + using the environment set up by runtests with: + + . "$C_TAP_SOURCE"/tap/libtap.sh + + Here is a complete test case written in shell which produces the same + output as the TAP sample above: + + #!/bin/sh + + . "$C_TAP_SOURCE"/tap/libtap.sh + cd "$C_TAP_BUILD" + + plan 4 + ok 'the first test' true + ok '' [ 42 -eq 42 ] + diag a diagnostic, ignored by the harness + ok '' false + skip 'a skipped test' + + The shell framework doesn't provide the is_* functions, so you'll use + the ok function more. It takes a string describing the text and then + treats all of its remaining arguments as a condition, evaluated the + same way as the arguments to the "if" statement. If that condition + evaluates to true, the test passes; otherwise, the test fails. + + The plan, plan_lazy, diag, and bail functions work the same as with + the C library. skip takes a string and skips the next test with that + explanation. skip_block takes a count and a string and skips that + many tests with that explanation. skip_all takes an optional reason + and skips the entire test case. + + Since it's common for shell programs to want to test the output of + commands, there's an additional function ok_program provided by the + shell test library. It takes the test description string, the + expected exit status, the expected program output, and then treats the + rest of its arguments as the program to run. That program is run with + standard error and standard output combined, and then its exit status + and output are tested against the provided values. + + A utility function, strip_colon_error, is provided that runs the + command given as its arguments and strips text following a colon and a + space from the output (unless there is no whitespace on the line + before the colon and the space, normally indicating a prefix of the + program name). This function can be used to wrap commands that are + expected to fail with output that has a system- or locale-specific + error message appended, such as the output of strerror(). + +License + + This file is part of the documentation of C TAP Harness, which can be + found at . + + Copyright 2010, 2016 Russ Allbery + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. This file is offered as-is, + without any warranty. + + SPDX-License-Identifier: FSFAP diff --git a/tests/client/basic-t.in b/tests/client/basic-t.in index 974b636..f9dc6dd 100644 --- a/tests/client/basic-t.in +++ b/tests/client/basic-t.in @@ -3,16 +3,17 @@ # Test suite for the wallet command-line client. # # Written by Russ Allbery -# Copyright 2006, 2007, 2008, 2010 +# Copyright 2018 Russ Allbery +# Copyright 2006-2008, 2010 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. # Load the test library. -. "$SOURCE/tap/libtap.sh" -. "$SOURCE/tap/kerberos.sh" -. "$SOURCE/tap/remctl.sh" -cd "$SOURCE" +. "$C_TAP_SOURCE/tap/libtap.sh" +. "$C_TAP_SOURCE/tap/kerberos.sh" +. "$C_TAP_SOURCE/tap/remctl.sh" +cd "$C_TAP_SOURCE" # We need a modified krb5.conf file to test wallet configuration settings in # krb5.conf. Despite the hard-coding of test-k5.stanford.edu, this test isn't @@ -54,8 +55,8 @@ elif [ -z '@REMCTLD@' ] ; then else plan 36 fi -remctld_start '@REMCTLD@' "$SOURCE/data/basic.conf" -wallet="$BUILD/../client/wallet" +remctld_start '@REMCTLD@' "$C_TAP_SOURCE/data/basic.conf" +wallet="$C_TAP_BUILD/../client/wallet" # Make sure everything's clean. rm -f output output.bak keytab keytab.bak srvtab srvtab.bak autocreated diff --git a/tests/client/full-t.in b/tests/client/full-t.in index 80bb20f..1ad486c 100644 --- a/tests/client/full-t.in +++ b/tests/client/full-t.in @@ -4,6 +4,7 @@ # End-to-end tests for the wallet client. # # Written by Russ Allbery +# Copyright 2018 Russ Allbery # Copyright 2008, 2010, 2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -14,14 +15,14 @@ use warnings; # Point to our server configuration. This must be done before Wallet::Config # is loaded, and it's pulled in as a prerequisite for Wallet::Admin. -BEGIN { $ENV{WALLET_CONFIG} = "$ENV{SOURCE}/data/wallet.conf" } +BEGIN { $ENV{WALLET_CONFIG} = "$ENV{C_TAP_SOURCE}/data/wallet.conf" } use Test::More tests => 59; -use lib "$ENV{SOURCE}/../perl/lib"; +use lib "$ENV{C_TAP_SOURCE}/../perl/lib"; use Wallet::Admin; -use lib "$ENV{SOURCE}/../perl/t/lib"; +use lib "$ENV{C_TAP_SOURCE}/../perl/t/lib"; use Util; # Make a call to the wallet client. Takes the principal used by the server @@ -37,9 +38,9 @@ sub wallet { or die "cannot create wallet.out: $!\n"; open (STDERR, '>', 'wallet.err') or die "cannot create wallet.err: $!\n"; - exec ("$ENV{BUILD}/../client/wallet", '-k', $principal, '-p', + exec ("$ENV{C_TAP_BUILD}/../client/wallet", '-k', $principal, '-p', '14373', '-s', 'localhost', @command) - or die "cannot run $ENV{BUILD}/client/wallet: $!\n"; + or die "cannot run $ENV{C_TAP_BUILD}/client/wallet: $!\n"; } else { waitpid ($pid, 0); } @@ -56,23 +57,23 @@ sub wallet { } # cd to the correct directory. -chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n"; +chdir "$ENV{C_TAP_SOURCE}" or die "Cannot chdir to $ENV{C_TAP_SOURCE}: $!\n"; SKIP: { skip 'no keytab configuration', 59 - unless -f "$ENV{BUILD}/config/keytab"; + unless -f "$ENV{C_TAP_BUILD}/config/keytab"; my $remctld = '@REMCTLD@'; skip 'remctld not found', 59 unless $remctld; # Spawn remctld and get local tickets. Don't destroy the user's Kerberos # ticket cache. unlink ('krb5cc_test', 'test-pid'); - my $principal = contents ("$ENV{BUILD}/config/principal"); + my $principal = contents ("$ENV{C_TAP_BUILD}/config/principal"); remctld_spawn ($remctld, $principal, - "$ENV{BUILD}/config/keytab", - "$ENV{SOURCE}/data/full.conf"); + "$ENV{C_TAP_BUILD}/config/keytab", + "$ENV{C_TAP_SOURCE}/data/full.conf"); $ENV{KRB5CCNAME} = 'krb5cc_test'; - getcreds ("$ENV{BUILD}/config/keytab", $principal); + getcreds ("$ENV{C_TAP_BUILD}/config/keytab", $principal); # Use Wallet::Admin to set up the database. db_setup; diff --git a/tests/client/prompt-t.in b/tests/client/prompt-t.in index d3a1eac..d5e9f17 100644 --- a/tests/client/prompt-t.in +++ b/tests/client/prompt-t.in @@ -4,6 +4,7 @@ # Password prompting tests for the wallet client. # # Written by Russ Allbery +# Copyright 2018 Russ Allbery # Copyright 2008, 2010, 2014 # The Board of Trustees of the Leland Stanford Junior University # @@ -14,18 +15,18 @@ use warnings; use Test::More tests => 5; -use lib "$ENV{SOURCE}/../perl/lib"; +use lib "$ENV{C_TAP_SOURCE}/../perl/lib"; use Wallet::Admin; -use lib "$ENV{SOURCE}/../perl/t/lib"; +use lib "$ENV{C_TAP_SOURCE}/../perl/t/lib"; use Util; # cd to the correct directory. -chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n"; +chdir "$ENV{C_TAP_SOURCE}" or die "Cannot chdir to $ENV{C_TAP_SOURCE}: $!\n"; SKIP: { skip 'no password configuration', 5 - unless -f "$ENV{BUILD}/config/password"; + unless -f "$ENV{C_TAP_BUILD}/config/password"; my $remctld = '@REMCTLD@'; skip 'remctld not found', 5 unless $remctld; eval { require Expect }; @@ -38,21 +39,21 @@ SKIP: { # Spawn remctld and set up with a different ticket cache. unlink ('krb5cc_test', 'test-pid'); - my $principal = contents ("$ENV{BUILD}/config/principal"); - remctld_spawn ($remctld, $principal, "$ENV{BUILD}/config/keytab", - "$ENV{SOURCE}/data/basic.conf"); + my $principal = contents ("$ENV{C_TAP_BUILD}/config/principal"); + remctld_spawn ($remctld, $principal, "$ENV{C_TAP_BUILD}/config/keytab", + "$ENV{C_TAP_SOURCE}/data/basic.conf"); $ENV{KRB5CCNAME} = 'krb5cc_test'; # Read in the principal and password. - open (PASS, '<', "$ENV{BUILD}/config/password") - or die "Cannot open $ENV{BUILD}/config/password: $!\n"; + open (PASS, '<', "$ENV{C_TAP_BUILD}/config/password") + or die "Cannot open $ENV{C_TAP_BUILD}/config/password: $!\n"; my $user = ; my $password = ; close PASS; chomp ($user, $password); # Spawn wallet and check an invalid password. - my $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k', + my $wallet = Expect->spawn ("$ENV{C_TAP_BUILD}/../client/wallet", '-k', $principal, '-p', 14373, '-s', 'localhost', '-c', 'fake-wallet', '-u', $user, 'get', 'keytab', 'service/fake-output'); @@ -63,7 +64,7 @@ SKIP: { $wallet->soft_close; # Now check a valid password. - $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k', + $wallet = Expect->spawn ("$ENV{C_TAP_BUILD}/../client/wallet", '-k', $principal, '-p', 14373, '-s', 'localhost', '-c', 'fake-wallet', '-u', $user, 'get', 'keytab', 'service/fake-output'); diff --git a/tests/client/rekey-t.in b/tests/client/rekey-t.in index c93b8eb..2e95a4e 100644 --- a/tests/client/rekey-t.in +++ b/tests/client/rekey-t.in @@ -3,16 +3,17 @@ # Test suite for the wallet-rekey command-line client. # # Written by Russ Allbery -# Copyright 2006, 2007, 2008, 2010 +# Copyright 2018 Russ Allbery +# Copyright 2006-2008, 2010 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. # Load the test library. -. "$SOURCE/tap/libtap.sh" -. "$SOURCE/tap/kerberos.sh" -. "$SOURCE/tap/remctl.sh" -cd "$SOURCE" +. "$C_TAP_SOURCE/tap/libtap.sh" +. "$C_TAP_SOURCE/tap/kerberos.sh" +. "$C_TAP_SOURCE/tap/remctl.sh" +cd "$C_TAP_SOURCE" # We need a modified krb5.conf file to test wallet configuration settings in # krb5.conf. Despite the hard-coding of test-k5.stanford.edu, this test isn't @@ -47,8 +48,8 @@ elif [ -z '@REMCTLD@' ] ; then else plan 8 fi -remctld_start '@REMCTLD@' "$SOURCE/data/basic.conf" -wallet="$BUILD/../client/wallet-rekey" +remctld_start '@REMCTLD@' "$C_TAP_SOURCE/data/basic.conf" +wallet="$C_TAP_BUILD/../client/wallet-rekey" # Rekeying should result in a merged keytab with both the old and new keys. cp data/fake-keytab-old keytab diff --git a/tests/data/cmd-wrapper b/tests/data/cmd-wrapper index b5b6d26..c2d5da1 100755 --- a/tests/data/cmd-wrapper +++ b/tests/data/cmd-wrapper @@ -3,6 +3,7 @@ # Wrapper around the standard wallet-backend script that sets the Perl INC # path and the WALLET_CONFIG environment variable appropriately. -WALLET_CONFIG="$SOURCE/data/wallet.conf" +WALLET_CONFIG="$C_TAP_SOURCE/data/wallet.conf" export WALLET_CONFIG -exec perl -I"$SOURCE/../perl/lib" "$SOURCE/../server/wallet-backend" -q "$@" +exec perl -I"$C_TAP_SOURCE/../perl/lib" \ + "$C_TAP_SOURCE/../server/wallet-backend" -q "$@" diff --git a/tests/docs/pod-spelling-t b/tests/docs/pod-spelling-t index 7b61c86..0419c24 100755 --- a/tests/docs/pod-spelling-t +++ b/tests/docs/pod-spelling-t @@ -3,10 +3,11 @@ # Checks all POD files in the tree for spelling errors using Test::Spelling. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2012, 2013, 2014 +# Copyright 2016 Russ Allbery +# Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -26,12 +27,14 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; use warnings; -use lib "$ENV{SOURCE}/tap/perl"; +use lib "$ENV{C_TAP_SOURCE}/tap/perl"; use Test::More; use Test::RRA qw(skip_unless_author use_prereq); diff --git a/tests/docs/pod-t b/tests/docs/pod-t index 53f9925..7ea3409 100755 --- a/tests/docs/pod-t +++ b/tests/docs/pod-t @@ -4,10 +4,11 @@ # distribution, for POD formatting errors. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2012, 2013, 2014 +# Copyright 2016 Russ Allbery +# Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -27,12 +28,14 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; use warnings; -use lib "$ENV{SOURCE}/tap/perl"; +use lib "$ENV{C_TAP_SOURCE}/tap/perl"; use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); diff --git a/tests/perl/minimum-version-t b/tests/perl/minimum-version-t index 8c49327..7d81b46 100755 --- a/tests/perl/minimum-version-t +++ b/tests/perl/minimum-version-t @@ -7,10 +7,11 @@ # required for internal tools than for public code. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2012, 2013, 2014 +# Copyright 2016 Russ Allbery +# Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -30,12 +31,14 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; use warnings; -use lib "$ENV{SOURCE}/tap/perl"; +use lib "$ENV{C_TAP_SOURCE}/tap/perl"; use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t index f1ebf0f..878cc2d 100755 --- a/tests/perl/module-version-t +++ b/tests/perl/module-version-t @@ -9,17 +9,19 @@ # # When given the --update option, instead fixes all of the Perl modules found # to have the correct version. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; use warnings; -# SOURCE may not be set if we're running this script manually to update +# C_TAP_SOURCE may not be set if we're running this script manually to update # version numbers. If it isn't, assume we're being run from the top of the # tree. BEGIN { - if ($ENV{SOURCE}) { - unshift(@INC, "$ENV{SOURCE}/tap/perl"); + if ($ENV{C_TAP_SOURCE}) { + unshift(@INC, "$ENV{C_TAP_SOURCE}/tap/perl"); } else { unshift(@INC, 'tests/tap/perl'); } @@ -178,6 +180,10 @@ SOFTWARE. =head1 SEE ALSO This module is maintained in the rra-c-util package. The current version is -available from L. +available from L. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: diff --git a/tests/perl/strict-t b/tests/perl/strict-t index 2df6d58..09ce157 100755 --- a/tests/perl/strict-t +++ b/tests/perl/strict-t @@ -7,10 +7,11 @@ # all pass a syntax check. Currently, test suite coverage is not checked. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2012, 2013, 2014 +# Copyright 2016 Russ Allbery +# Copyright 2012-2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -30,12 +31,14 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT use 5.006; use strict; use warnings; -use lib "$ENV{SOURCE}/tap/perl"; +use lib "$ENV{C_TAP_SOURCE}/tap/perl"; use Test::More; use Test::RRA qw(skip_unless_automated use_prereq); @@ -46,7 +49,7 @@ use Test::RRA::Config qw(@STRICT_IGNORE @STRICT_PREREQ); skip_unless_automated('Strictness tests'); # Load prerequisite modules. -use_prereq('Test::Strict'); +use_prereq('Test::Strict', '0.25'); # Check whether all prerequisites are available, and skip the test if any of # them are not. diff --git a/tests/portable/asprintf-t.c b/tests/portable/asprintf-t.c index e556d95..3b10a66 100644 --- a/tests/portable/asprintf-t.c +++ b/tests/portable/asprintf-t.c @@ -2,17 +2,19 @@ * asprintf and vasprintf test suite. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2014, 2018 Russ Allbery + * Copyright 2006-2009, 2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include @@ -23,9 +25,10 @@ int test_asprintf(char **, const char *, ...) __attribute__((__format__(printf, 2, 3))); -int test_vasprintf(char **, const char *, va_list); +int test_vasprintf(char **, const char *, va_list) + __attribute__((__format__(printf, 2, 0))); -static int +static int __attribute__((__format__(printf, 2, 3))) vatest(char **result, const char *format, ...) { va_list args; diff --git a/tests/portable/mkstemp-t.c b/tests/portable/mkstemp-t.c index 20a83fc..dc26821 100644 --- a/tests/portable/mkstemp-t.c +++ b/tests/portable/mkstemp-t.c @@ -2,17 +2,18 @@ * mkstemp test suite. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2009, 2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include diff --git a/tests/portable/setenv-t.c b/tests/portable/setenv-t.c index 15ed1fd..92a8c95 100644 --- a/tests/portable/setenv-t.c +++ b/tests/portable/setenv-t.c @@ -2,17 +2,19 @@ * setenv test suite. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2000-2006, 2017 Russ Allbery + * Copyright 2006-2009, 2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #include diff --git a/tests/portable/snprintf-t.c b/tests/portable/snprintf-t.c index cc8cf00..7e8a68f 100644 --- a/tests/portable/snprintf-t.c +++ b/tests/portable/snprintf-t.c @@ -2,12 +2,11 @@ * snprintf test suite. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 - * Russ Allbery - * Copyright 2009, 2010 + * Copyright 2000-2006, 2018 Russ Allbery + * Copyright 2009-2010 * The Board of Trustees of the Leland Stanford Junior University * Copyright 1995 Patrick Powell * Copyright 2001 Hrvoje Niksic @@ -15,6 +14,8 @@ * This code is based on code written by Patrick Powell (papowell@astart.com) * It may be used for any purpose as long as this notice remains intact * on all source code distributions + * + * There is no SPDX-License-Identifier registered for this license. */ #include @@ -159,7 +160,7 @@ main(void) &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", NULL); + test_format(true, "(null)", 6, "%s", (char *) NULL); for (i = 0; fp_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(fp_nums); j++) { diff --git a/tests/runtests.c b/tests/runtests.c index 42a73ea..af15a5c 100644 --- a/tests/runtests.c +++ b/tests/runtests.c @@ -1,6 +1,37 @@ /* * Run a set of tests, reporting results. * + * Test suite driver that runs a set of tests implementing a subset of the + * Test Anything Protocol (TAP) and reports the results. + * + * Any bug reports, bug fixes, and improvements are very much welcome and + * 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 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + */ + +/* * Usage: * * runtests [-hv] [-b ] [-s ] -l @@ -8,9 +39,10 @@ * runtests -o [-h] [-b ] [-s ] * * In the first case, expects a list of executables located in the given file, - * one line per executable. For each one, runs it as part of a test suite, - * reporting results. In the second case, use the same infrastructure, but - * run only the tests listed on the command line. + * one line per executable, possibly followed by a space-separated list of + * options. For each one, runs it as part of a test suite, reporting results. + * In the second case, use the same infrastructure, but run only the tests + * listed on the command line. * * Test output should start with a line containing the number of tests * (numbered from 1 to this number), optionally preceded by "1..", although @@ -48,41 +80,16 @@ * output. This is intended for use with failing tests so that the person * running the test suite can get more details about what failed. * - * If built with the C preprocessor symbols SOURCE and BUILD defined, C TAP - * Harness will export those values in the environment so that tests can find - * the source and build directory and will look for tests under both - * directories. These paths can also be set with the -b and -s command-line - * options, which will override anything set at build time. + * If built with the C preprocessor symbols C_TAP_SOURCE and C_TAP_BUILD + * defined, C TAP Harness will export those values in the environment so that + * tests can find the source and build directory and will look for tests under + * both directories. These paths can also be set with the -b and -s + * command-line options, which will override anything set at build time. * * If the -v option is given, or the C_TAP_VERBOSE environment variable is set, * display the full output of each test as it runs rather than showing a * summary of the results of each test. - * - * Any bug reports, bug fixes, and improvements are very much welcome and - * should be sent to the e-mail address below. This program is part of C TAP - * Harness . - * - * Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, - * 2014, 2015 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 in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. -*/ + */ /* Required for fdopen(), getopt(), and putenv(). */ #if defined(__STRICT_ANSI__) || defined(PEDANTIC) @@ -135,15 +142,17 @@ /* * The source and build versions of the tests directory. This is used to set - * the SOURCE and BUILD environment variables and find test programs, if set. - * Normally, this should be set as part of the build process to the test - * subdirectories of $(abs_top_srcdir) and $(abs_top_builddir) respectively. + * the C_TAP_SOURCE and C_TAP_BUILD environment variables (and the SOURCE and + * BUILD environment variables set for backward compatibility) and find test + * programs, if set. Normally, this should be set as part of the build + * process to the test subdirectories of $(abs_top_srcdir) and + * $(abs_top_builddir) respectively. */ -#ifndef SOURCE -# define SOURCE NULL +#ifndef C_TAP_SOURCE +# define C_TAP_SOURCE NULL #endif -#ifndef BUILD -# define BUILD NULL +#ifndef C_TAP_BUILD +# define C_TAP_BUILD NULL #endif /* Test status codes. */ @@ -177,7 +186,7 @@ enum plan_status { /* Structure to hold data for a set of tests. */ struct testset { char *file; /* The file name of the test. */ - char *path; /* The path to the test program. */ + 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. */ @@ -188,7 +197,7 @@ struct testset { 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. */ - int reported; /* Whether the results were reported. */ + 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. */ @@ -240,6 +249,7 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ #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__) @@ -280,6 +290,8 @@ Failed Set Fail/Total (%) Skip Stat Failing Tests\n\ #endif /* Declare internal functions that benefit from compiler attributes. */ +static void die(const char *, ...) + __attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2))); static void sysdie(const char *, ...) __attribute__((__nonnull__, __noreturn__, __format__(printf, 1, 2))); static void *x_calloc(size_t, size_t, const char *, int) @@ -290,6 +302,26 @@ static void *x_reallocarray(void *, size_t, size_t, const char *, int) __attribute__((__alloc_size__(2, 3), __malloc__, __nonnull__(4))); static char *x_strdup(const char *, const char *, int) __attribute__((__malloc__, __nonnull__)); +static char *x_strndup(const char *, size_t, const char *, int) + __attribute__((__malloc__, __nonnull__)); + + +/* + * Report a fatal error and exit. + */ +static void +die(const char *format, ...) +{ + va_list args; + + fflush(stdout); + fprintf(stderr, "runtests: "); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + fprintf(stderr, "\n"); + exit(1); +} /* @@ -391,6 +423,35 @@ x_strdup(const char *s, const char *file, int line) } +/* + * Copy the first n characters of a string, reporting a fatal error and + * existing on failure. + * + * Avoid using the system strndup function since it may not exist (on Mac OS + * X, for example), and there's no need to introduce another portability + * requirement. + */ +char * +x_strndup(const char *s, size_t size, const char *file, int line) +{ + const char *p; + size_t len; + char *copy; + + /* Don't assume that the source string is nul-terminated. */ + for (p = s; (size_t) (p - s) < size && *p != '\0'; p++) + ; + len = (size_t) (p - s); + copy = malloc(len + 1); + if (copy == NULL) + sysdie("failed to strndup %lu bytes at %s line %d", + (unsigned long) len, file, line); + memcpy(copy, s, len); + copy[len] = '\0'; + return copy; +} + + /* * Form a new string by concatenating multiple strings. The arguments must be * terminated by (const char *) 0. @@ -447,7 +508,7 @@ concat(const char *first, ...) static double tv_seconds(const struct timeval *tv) { - return difftime(tv->tv_sec, 0) + tv->tv_usec * 1e-6; + return difftime(tv->tv_sec, 0) + (double) tv->tv_usec * 1e-6; } @@ -484,13 +545,26 @@ skip_whitespace(const char *p) } +/* + * Given a pointer to a string, skip any non-whitespace characters and return + * a pointer to the first whitespace character, or to the end of the string. + */ +static const char * +skip_non_whitespace(const char *p) +{ + while (*p != '\0' && !isspace((unsigned char)(*p))) + p++; + return p; +} + + /* * Start a program, connecting its stdout to a pipe on our end and its stderr * to /dev/null, and storing the file descriptor to read from in the two * argument. Returns the PID of the new process. Errors are fatal. */ static pid_t -test_start(const char *path, int *fd) +test_start(char *const *command, int *fd) { int fds[2], infd, errfd; pid_t child; @@ -541,8 +615,9 @@ test_start(const char *path, int *fd) } /* Now, exec our process. */ - if (execl(path, path, (char *) 0) == -1) + if (execv(command[0], command) == -1) _exit(CHILDERR_EXEC); + break; /* In parent. Close the extra file descriptor. */ default: @@ -1035,7 +1110,7 @@ test_run(struct testset *ts, enum test_verbose verbose) char buffer[BUFSIZ]; /* Run the test program. */ - testpid = test_start(ts->path, &outfd); + testpid = test_start(ts->command, &outfd); output = fdopen(outfd, "r"); if (!output) { puts("ABORTED"); @@ -1097,6 +1172,7 @@ test_fail_summary(const struct testlist *fails) struct testset *ts; unsigned int chars; unsigned long i, first, last, total; + double failed; puts(header); @@ -1105,8 +1181,9 @@ test_fail_summary(const struct testlist *fails) for (; fails; fails = fails->next) { ts = fails->ts; total = ts->count - ts->skipped; + failed = (double) ts->failed; printf("%-26.26s %4lu/%-4lu %3.0f%% %4lu ", ts->file, ts->failed, - total, total ? (ts->failed * 100.0) / total : 0, + total, total ? (failed * 100.0) / (double) total : 0, ts->skipped); if (WIFEXITED(ts->status)) printf("%4d ", WEXITSTATUS(ts->status)); @@ -1202,6 +1279,98 @@ find_test(const char *name, const char *source, const char *build) } +/* + * Parse a single line of a test list and store the test name and command to + * execute it in the given testset struct. + * + * Normally, each line is just the name of the test, which is located in the + * test directory and turned into a command to run. However, each line may + * have whitespace-separated options, which change the command that's run. + * Current supported options are: + * + * valgrind + * Run the test under valgrind if C_TAP_VALGRIND is set. The contents + * of that environment variable are taken as the valgrind command (with + * options) to run. The command is parsed with a simple split on + * whitespace and no quoting is supported. + * + * libtool + * If running under valgrind, use libtool to invoke valgrind. This avoids + * running valgrind on the wrapper shell script generated by libtool. If + * set, C_TAP_LIBTOOL must be set to the full path to the libtool program + * to use to run valgrind and thus the test. Ignored if the test isn't + * being run under valgrind. + */ +static void +parse_test_list_line(const char *line, struct testset *ts, const char *source, + const char *build) +{ + const char *p, *end, *option, *libtool; + const char *valgrind = NULL; + unsigned int use_libtool = 0; + unsigned int use_valgrind = 0; + size_t len, i; + + /* Determine the name of the test. */ + p = skip_non_whitespace(line); + ts->file = xstrndup(line, p - line); + + /* Check if any test options are set. */ + p = skip_whitespace(p); + while (*p != '\0') { + 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); + } + p = skip_whitespace(end); + } + + /* Construct the argv to run the test. First, find the length. */ + len = 1; + if (use_valgrind && valgrind != NULL) { + p = skip_whitespace(valgrind); + while (*p != '\0') { + len++; + p = skip_whitespace(skip_non_whitespace(p)); + } + if (use_libtool) + len += 2; + } + + /* Now, build the command. */ + ts->command = xcalloc(len + 1, sizeof(char *)); + i = 0; + if (use_valgrind && valgrind != NULL) { + if (use_libtool) { + libtool = getenv("C_TAP_LIBTOOL"); + if (libtool == NULL) + die("valgrind with libtool requested, but C_TAP_LIBTOOL is not" + " set"); + ts->command[i++] = xstrdup(libtool); + ts->command[i++] = xstrdup("--mode=execute"); + } + p = skip_whitespace(valgrind); + while (*p != '\0') { + end = skip_non_whitespace(p); + ts->command[i++] = xstrndup(p, end - p); + p = skip_whitespace(end); + } + } + if (i != len - 1) + die("internal error while constructing command line"); + ts->command[i++] = find_test(ts->file, source, build); + ts->command[i] = NULL; +} + + /* * Read a list of tests from a file, returning the list of tests as a struct * testlist, or NULL if there were no tests (such as a file containing only @@ -1209,13 +1378,13 @@ find_test(const char *name, const char *source, const char *build) * tests cannot be read. */ static struct testlist * -read_test_list(const char *filename) +read_test_list(const char *filename, const char *source, const char *build) { FILE *file; unsigned int line; size_t length; char buffer[BUFSIZ]; - const char *testname; + const char *start; struct testlist *listhead, *current; /* Create the initial container list that will hold our results. */ @@ -1240,10 +1409,10 @@ read_test_list(const char *filename) buffer[length] = '\0'; /* Skip comments, leading spaces, and blank lines. */ - testname = skip_whitespace(buffer); - if (strlen(testname) == 0) + start = skip_whitespace(buffer); + if (strlen(start) == 0) continue; - if (testname[0] == '#') + if (start[0] == '#') continue; /* Allocate the new testset structure. */ @@ -1255,7 +1424,9 @@ read_test_list(const char *filename) } current->ts = xcalloc(1, sizeof(struct testset)); current->ts->plan = PLAN_INIT; - current->ts->file = xstrdup(testname); + + /* Parse the line and store the results in the testset struct. */ + parse_test_list_line(start, current->ts, source, build); } fclose(file); @@ -1277,7 +1448,7 @@ read_test_list(const char *filename) * freeing. */ static struct testlist * -build_test_list(char *argv[], int argc) +build_test_list(char *argv[], int argc, const char *source, const char *build) { int i; struct testlist *listhead, *current; @@ -1297,6 +1468,9 @@ build_test_list(char *argv[], int argc) current->ts = xcalloc(1, sizeof(struct testset)); current->ts->plan = PLAN_INIT; current->ts->file = xstrdup(argv[i]); + current->ts->command = xcalloc(2, sizeof(char *)); + current->ts->command[0] = find_test(current->ts->file, source, build); + current->ts->command[1] = NULL; } /* If there were no tests, current is still NULL. */ @@ -1314,8 +1488,12 @@ build_test_list(char *argv[], int argc) static void free_testset(struct testset *ts) { + size_t i; + free(ts->file); - free(ts->path); + for (i = 0; ts->command[i] != NULL; i++) + free(ts->command[i]); + free(ts->command); free(ts->results); free(ts->reason); free(ts); @@ -1330,8 +1508,7 @@ free_testset(struct testset *ts) * frees the test list that's passed in. */ static int -test_batch(struct testlist *tests, const char *source, const char *build, - enum test_verbose verbose) +test_batch(struct testlist *tests, enum test_verbose verbose) { size_t length, i; size_t longest = 0; @@ -1382,7 +1559,6 @@ test_batch(struct testlist *tests, const char *source, const char *build, fflush(stdout); /* Run the test. */ - ts->path = find_test(ts->file, source, build); succeeded = test_run(ts, verbose); fflush(stdout); if (verbose) @@ -1446,7 +1622,7 @@ test_batch(struct testlist *tests, const char *source, const char *build, fputs("All tests successful", stdout); else printf("Failed %lu/%lu tests, %.2f%% okay", failed, total, - (total - failed) * 100.0 / total); + (double) (total - failed) * 100.0 / (double) total); if (skipped != 0) { if (skipped == 1) printf(", %lu test skipped", skipped); @@ -1479,8 +1655,9 @@ test_single(const char *program, const char *source, const char *build) /* - * Main routine. Set the SOURCE and BUILD environment variables and then, - * given a file listing tests, run each test listed. + * Main routine. Set the C_TAP_SOURCE, C_TAP_BUILD, SOURCE, and BUILD + * environment variables and then, given a file listing tests, run each test + * listed. */ int main(int argc, char *argv[]) @@ -1489,13 +1666,15 @@ main(int argc, char *argv[]) int status = 0; int single = 0; enum test_verbose verbose = CONCISE; + char *c_tap_source_env = NULL; + char *c_tap_build_env = NULL; char *source_env = NULL; char *build_env = NULL; const char *program; const char *shortlist; const char *list = NULL; - const char *source = SOURCE; - const char *build = BUILD; + const char *source = C_TAP_SOURCE; + const char *build = C_TAP_BUILD; struct testlist *tests; program = argv[0]; @@ -1537,13 +1716,23 @@ main(int argc, char *argv[]) if (getenv("C_TAP_VERBOSE") != NULL) verbose = VERBOSE; - /* Set SOURCE and BUILD environment variables. */ + /* + * Set C_TAP_SOURCE and C_TAP_BUILD environment variables. Also set + * SOURCE and BUILD for backward compatibility, although we're trying to + * migrate to the ones with a C_TAP_* prefix. + */ if (source != NULL) { + c_tap_source_env = concat("C_TAP_SOURCE=", source, (const char *) 0); + if (putenv(c_tap_source_env) != 0) + sysdie("cannot set C_TAP_SOURCE in the environment"); source_env = concat("SOURCE=", source, (const char *) 0); if (putenv(source_env) != 0) sysdie("cannot set SOURCE in the environment"); } if (build != NULL) { + c_tap_build_env = concat("C_TAP_BUILD=", build, (const char *) 0); + if (putenv(c_tap_build_env) != 0) + sysdie("cannot set C_TAP_BUILD in the environment"); build_env = concat("BUILD=", build, (const char *) 0); if (putenv(build_env) != 0) sysdie("cannot set BUILD in the environment"); @@ -1559,20 +1748,24 @@ main(int argc, char *argv[]) else shortlist++; printf(banner, shortlist); - tests = read_test_list(list); - status = test_batch(tests, source, build, verbose) ? 0 : 1; + tests = read_test_list(list, source, build); + status = test_batch(tests, verbose) ? 0 : 1; } else { - tests = build_test_list(argv, argc); - status = test_batch(tests, source, build, verbose) ? 0 : 1; + tests = build_test_list(argv, argc, source, build); + status = test_batch(tests, verbose) ? 0 : 1; } /* For valgrind cleanliness, free all our memory. */ if (source_env != NULL) { + putenv((char *) "C_TAP_SOURCE="); putenv((char *) "SOURCE="); + free(c_tap_source_env); free(source_env); } if (build_env != NULL) { + putenv((char *) "C_TAP_BUILD="); putenv((char *) "BUILD="); + free(c_tap_build_env); free(build_env); } exit(status); diff --git a/tests/server/admin-t b/tests/server/admin-t index f025d98..8fde012 100755 --- a/tests/server/admin-t +++ b/tests/server/admin-t @@ -3,7 +3,8 @@ # Tests for the wallet-admin dispatch code. # # Written by Russ Allbery -# Copyright 2008, 2009, 2010, 2011, 2014 +# Copyright 2018 Russ Allbery +# Copyright 2008-2011, 2014 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. @@ -68,7 +69,7 @@ sub upgrade { # Wallet::Admin package has already been loaded. package main; $INC{'Wallet/Admin.pm'} = 'FAKE'; -eval { do "$ENV{SOURCE}/../server/wallet-admin" }; +eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-admin" }; # Run the wallet admin client. This fun hack takes advantage of the fact that # the wallet admin client is written in Perl so that we can substitute our own diff --git a/tests/server/backend-t b/tests/server/backend-t index 2ed8404..e8ea1ce 100755 --- a/tests/server/backend-t +++ b/tests/server/backend-t @@ -3,7 +3,8 @@ # Tests for the wallet-backend dispatch code. # # Written by Russ Allbery -# Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 +# Copyright 2018 Russ Allbery +# Copyright 2006-2014 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. @@ -189,7 +190,7 @@ $INC{'Wallet/Server.pm'} = 'FAKE'; my $OUTPUT; our $SYSLOG = \$OUTPUT; my $INPUT = ''; -eval { do "$ENV{SOURCE}/../server/wallet-backend" }; +eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-backend" }; # Run the wallet backend. This fun hack takes advantage of the fact that the # wallet backend is written in Perl so that we can substitute our own diff --git a/tests/server/keytab-t b/tests/server/keytab-t index 94c1bd8..00c6e92 100755 --- a/tests/server/keytab-t +++ b/tests/server/keytab-t @@ -3,7 +3,8 @@ # Tests for the keytab-backend dispatch code. # # Written by Russ Allbery -# Copyright 2006, 2007, 2010 +# Copyright 2018 Russ Allbery +# Copyright 2006-2007, 2010 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. @@ -16,9 +17,9 @@ use Test::More tests => 63; # Load the keytab-backend code and override various settings. my $OUTPUT; $SYSLOG = \$OUTPUT; -eval { do "$ENV{SOURCE}/../server/keytab-backend" }; -$CONFIG = "$ENV{SOURCE}/data/allow-extract"; -$KADMIN = "$ENV{SOURCE}/data/fake-kadmin"; +eval { do "$ENV{C_TAP_SOURCE}/../server/keytab-backend" }; +$CONFIG = "$ENV{C_TAP_SOURCE}/data/allow-extract"; +$KADMIN = "$ENV{C_TAP_SOURCE}/data/fake-kadmin"; $TMP = '.'; # Run the keytab backend. diff --git a/tests/server/report-t b/tests/server/report-t index ad05363..2e0cef7 100755 --- a/tests/server/report-t +++ b/tests/server/report-t @@ -3,7 +3,8 @@ # Tests for the wallet-report dispatch code. # # Written by Russ Allbery -# Copyright 2008, 2009, 2010 +# Copyright 2018 Russ Allbery +# Copyright 2008-2010 # The Board of Trustees of the Leland Stanford Junior University # # See LICENSE for licensing terms. @@ -72,7 +73,7 @@ sub owners { # Wallet::Report package has already been loaded. package main; $INC{'Wallet/Report.pm'} = 'FAKE'; -eval { do "$ENV{SOURCE}/../server/wallet-report" }; +eval { do "$ENV{C_TAP_SOURCE}/../server/wallet-report" }; # Run the wallet report client. This fun hack takes advantage of the fact # that the wallet report client is written in Perl so that we can substitute diff --git a/tests/tap/basic.c b/tests/tap/basic.c index 4f8be04..8624839 100644 --- a/tests/tap/basic.c +++ b/tests/tap/basic.c @@ -10,11 +10,11 @@ * up the TAP output format, or finding things in the test environment. * * This file is part of C TAP Harness. The current version plus supporting - * documentation is at . + * documentation is at . * - * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015 - * Russ Allbery - * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2013, 2014 + * Written by Russ Allbery + * Copyright 2009-2018 Russ Allbery + * Copyright 2001-2002, 2004-2008, 2011-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -34,6 +34,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -128,8 +130,7 @@ static struct diag_file *diag_files = NULL; do { \ if (format != NULL) { \ va_list args; \ - if (prefix != NULL) \ - printf("%s", prefix); \ + printf("%s", prefix); \ va_start(args, format); \ vprintf(format, args); \ va_end(args); \ @@ -489,22 +490,81 @@ skip_block(unsigned long count, const char *reason, ...) /* - * Takes an expected integer and a seen integer and assumes the test passes - * if those two numbers match. + * Takes two boolean values and requires the truth value of both match. + */ +int +is_bool(int left, int right, const char *format, ...) +{ + int success; + + fflush(stderr); + check_diag_files(); + success = (!!left == !!right); + if (success) + printf("ok %lu", testnum++); + else { + diag(" left: %s", !!left ? "true" : "false"); + diag("right: %s", !!right ? "true" : "false"); + printf("not ok %lu", testnum++); + _failed++; + } + PRINT_DESC(" - ", format); + putchar('\n'); + return success; +} + + +/* + * Takes two integer values and requires they match. + */ +int +is_int(long left, long right, const char *format, ...) +{ + int success; + + fflush(stderr); + check_diag_files(); + success = (left == right); + if (success) + printf("ok %lu", testnum++); + else { + diag(" left: %ld", left); + diag("right: %ld", right); + printf("not ok %lu", testnum++); + _failed++; + } + PRINT_DESC(" - ", format); + putchar('\n'); + return success; +} + + +/* + * Takes two strings and requires they match (using strcmp). NULL arguments + * are permitted and handled correctly. */ int -is_int(long wanted, long seen, const char *format, ...) +is_string(const char *left, const char *right, const char *format, ...) { int success; fflush(stderr); check_diag_files(); - success = (wanted == seen); + + /* Compare the strings, being careful of NULL. */ + if (left == NULL) + success = (right == NULL); + else if (right == NULL) + success = 0; + else + success = (strcmp(left, right) == 0); + + /* Report the results. */ if (success) printf("ok %lu", testnum++); else { - diag("wanted: %ld", wanted); - diag(" seen: %ld", seen); + diag(" left: %s", left == NULL ? "(null)" : left); + diag("right: %s", right == NULL ? "(null)" : right); printf("not ok %lu", testnum++); _failed++; } @@ -515,26 +575,22 @@ is_int(long wanted, long seen, const char *format, ...) /* - * Takes a string and what the string should be, and assumes the test passes - * if those strings match (using strcmp). + * Takes two unsigned longs and requires they match. On failure, reports them + * in hex. */ int -is_string(const char *wanted, const char *seen, const char *format, ...) +is_hex(unsigned long left, unsigned long right, const char *format, ...) { int success; - if (wanted == NULL) - wanted = "(null)"; - if (seen == NULL) - seen = "(null)"; fflush(stderr); check_diag_files(); - success = (strcmp(wanted, seen) == 0); + success = (left == right); if (success) printf("ok %lu", testnum++); else { - diag("wanted: %s", wanted); - diag(" seen: %s", seen); + diag(" left: %lx", (unsigned long) left); + diag("right: %lx", (unsigned long) right); printf("not ok %lu", testnum++); _failed++; } @@ -545,22 +601,30 @@ is_string(const char *wanted, const char *seen, const char *format, ...) /* - * Takes an expected unsigned long and a seen unsigned long and assumes the - * test passes if the two numbers match. Otherwise, reports them in hex. + * Takes pointers to a regions of memory and requires that len bytes from each + * match. Otherwise reports any bytes which didn't match. */ int -is_hex(unsigned long wanted, unsigned long seen, const char *format, ...) +is_blob(const void *left, const void *right, size_t len, const char *format, + ...) { int success; + size_t i; fflush(stderr); check_diag_files(); - success = (wanted == seen); + success = (memcmp(left, right, len) == 0); if (success) printf("ok %lu", testnum++); else { - diag("wanted: %lx", (unsigned long) wanted); - diag(" seen: %lx", (unsigned long) seen); + const unsigned char *left_c = left; + const unsigned char *right_c = right; + + for (i = 0; i < len; i++) { + if (left_c[i] != right_c[i]) + diag("offset %lu: left %02x, right %02x", (unsigned long) i, + left_c[i], right_c[i]); + } printf("not ok %lu", testnum++); _failed++; } @@ -769,6 +833,8 @@ breallocarray(void *p, size_t n, size_t size) { if (n > 0 && UINT_MAX / n <= size) bail("reallocarray too large"); + if (n == 0) + n = 1; p = realloc(p, n * size); if (p == NULL) sysbail("failed to realloc %lu bytes", (unsigned long) (n * size)); @@ -820,17 +886,17 @@ bstrndup(const char *s, size_t n) /* - * Locate a test file. Given the partial path to a file, look under BUILD and - * then SOURCE for the file and return the full path to the file. Returns - * NULL if the file doesn't exist. A non-NULL return should be freed with - * test_file_path_free(). + * Locate a test file. Given the partial path to a file, look under + * C_TAP_BUILD and then C_TAP_SOURCE for the file and return the full path to + * the file. Returns NULL if the file doesn't exist. A non-NULL return + * should be freed with test_file_path_free(). */ char * test_file_path(const char *file) { char *base; char *path = NULL; - const char *envs[] = { "BUILD", "SOURCE", NULL }; + const char *envs[] = { "C_TAP_BUILD", "C_TAP_SOURCE", NULL }; int i; for (i = 0; envs[i] != NULL; i++) { @@ -860,7 +926,7 @@ test_file_path_free(char *path) /* - * Create a temporary directory, tmp, under BUILD if set and the current + * Create a temporary directory, tmp, under C_TAP_BUILD if set and the current * directory if it does not. Returns the path to the temporary directory in * newly allocated memory, and calls bail on any failure. The return value * should be freed with test_tmpdir_free. @@ -875,7 +941,7 @@ test_tmpdir(void) const char *build; char *path = NULL; - build = getenv("BUILD"); + build = getenv("C_TAP_BUILD"); if (build == NULL) build = "."; path = concat(build, "/tmp", (const char *) 0); diff --git a/tests/tap/basic.h b/tests/tap/basic.h index 4ecaaec..3f46e4f 100644 --- a/tests/tap/basic.h +++ b/tests/tap/basic.h @@ -2,11 +2,11 @@ * Basic utility routines for the TAP protocol. * * This file is part of C TAP Harness. The current version plus supporting - * documentation is at . + * documentation is at . * - * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015 - * Russ Allbery - * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2014 + * Written by Russ Allbery + * Copyright 2009-2018 Russ Allbery + * Copyright 2001-2002, 2004-2008, 2011-2012, 2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_BASIC_H @@ -88,15 +90,21 @@ void skip_block(unsigned long count, const char *reason, ...) __attribute__((__format__(printf, 2, 3))); /* - * Check an expected value against a seen value. Returns true if the test - * passes and false if it fails. + * Compare two values. Returns true if the test passes and false if it fails. + * is_bool takes an int since the bool type isn't fully portable yet, but + * interprets both arguments for their truth value, not for their numeric + * value. */ -int is_int(long wanted, long seen, const char *format, ...) +int is_bool(int, int, const char *format, ...) + __attribute__((__format__(printf, 3, 4))); +int is_int(long, long, const char *format, ...) __attribute__((__format__(printf, 3, 4))); -int is_string(const char *wanted, const char *seen, const char *format, ...) +int is_string(const char *, const char *, const char *format, ...) __attribute__((__format__(printf, 3, 4))); -int is_hex(unsigned long wanted, unsigned long seen, const char *format, ...) +int is_hex(unsigned long, unsigned long, const char *format, ...) __attribute__((__format__(printf, 3, 4))); +int is_blob(const void *, const void *, size_t, const char *format, ...) + __attribute__((__format__(printf, 4, 5))); /* Bail out with an error. sysbail appends strerror(errno). */ void bail(const char *format, ...) @@ -137,16 +145,16 @@ char *bstrndup(const char *, size_t) __attribute__((__malloc__, __nonnull__, __warn_unused_result__)); /* - * Find a test file under BUILD or SOURCE, returning the full path. The - * returned path should be freed with test_file_path_free(). + * 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(). */ char *test_file_path(const char *file) __attribute__((__malloc__, __nonnull__, __warn_unused_result__)); void test_file_path_free(char *path); /* - * Create a temporary directory relative to BUILD and return the path. The - * returned path should be freed with test_tmpdir_free. + * 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__)); diff --git a/tests/tap/kerberos.c b/tests/tap/kerberos.c index 6a5025a..89a36a3 100644 --- a/tests/tap/kerberos.c +++ b/tests/tap/kerberos.c @@ -12,10 +12,11 @@ * are available. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014 + * Copyright 2017 Russ Allbery + * Copyright 2006-2007, 2009-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -35,6 +36,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -361,7 +364,7 @@ kerberos_setup(enum kerberos_needs needs) path = test_file_path("config/pkinit-principal"); if (path != NULL) file = fopen(path, "r"); - if (file != NULL) { + if (path != NULL && file != NULL) { if (fgets(buffer, sizeof(buffer), file) == NULL) bail("cannot read %s", path); if (buffer[strlen(buffer) - 1] != '\n') @@ -457,17 +460,19 @@ kerberos_generate_conf(const char *realm) /* - * Report a Kerberos error and bail out. + * Report a Kerberos error and bail out. Takes a long instead of a + * krb5_error_code because it can also handle a kadm5_ret_t (which may be a + * different size). */ void -bail_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...) +bail_krb5(krb5_context ctx, long code, const char *format, ...) { const char *k5_msg = NULL; char *message; va_list args; if (ctx != NULL) - k5_msg = krb5_get_error_message(ctx, code); + k5_msg = krb5_get_error_message(ctx, (krb5_error_code) code); va_start(args, format); bvasprintf(&message, format, args); va_end(args); @@ -479,17 +484,19 @@ bail_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...) /* - * Report a Kerberos error as a diagnostic to stderr. + * Report a Kerberos error as a diagnostic to stderr. Takes a long instead of + * a krb5_error_code because it can also handle a kadm5_ret_t (which may be a + * different size). */ void -diag_krb5(krb5_context ctx, krb5_error_code code, const char *format, ...) +diag_krb5(krb5_context ctx, long code, const char *format, ...) { const char *k5_msg = NULL; char *message; va_list args; if (ctx != NULL) - k5_msg = krb5_get_error_message(ctx, code); + k5_msg = krb5_get_error_message(ctx, (krb5_error_code) code); va_start(args, format); bvasprintf(&message, format, args); va_end(args); @@ -524,14 +531,12 @@ kerberos_keytab_principal(krb5_context ctx, const char *path) if (status != 0) bail_krb5(ctx, status, "error reading %s", path); status = krb5_kt_next_entry(ctx, keytab, &entry, &cursor); - if (status == 0) { - status = krb5_copy_principal(ctx, entry.principal, &princ); - if (status != 0) - bail_krb5(ctx, status, "error copying principal from %s", path); - krb5_kt_free_entry(ctx, &entry); - } if (status != 0) bail("no principal found in keytab file %s", path); + status = krb5_copy_principal(ctx, entry.principal, &princ); + if (status != 0) + bail_krb5(ctx, status, "error copying principal from %s", path); + krb5_kt_free_entry(ctx, &entry); krb5_kt_end_seq_get(ctx, keytab, &cursor); krb5_kt_close(ctx, keytab); return princ; diff --git a/tests/tap/kerberos.h b/tests/tap/kerberos.h index 26f45f9..c256822 100644 --- a/tests/tap/kerberos.h +++ b/tests/tap/kerberos.h @@ -2,10 +2,11 @@ * Utility functions for tests that use Kerberos. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2006, 2007, 2009, 2011, 2012, 2013, 2014 + * Copyright 2017 Russ Allbery + * Copyright 2006-2007, 2009, 2011-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_KERBEROS_H @@ -107,12 +110,12 @@ void kerberos_cleanup_conf(void); #ifdef HAVE_KRB5 /* Bail out with an error, appending the Kerberos error message. */ -void bail_krb5(krb5_context, krb5_error_code, const char *format, ...) - __attribute__((__noreturn__, __nonnull__, __format__(printf, 3, 4))); +void bail_krb5(krb5_context, long, const char *format, ...) + __attribute__((__noreturn__, __nonnull__(3), __format__(printf, 3, 4))); /* Report a diagnostic with Kerberos error to stderr prefixed with #. */ -void diag_krb5(krb5_context, krb5_error_code, const char *format, ...) - __attribute__((__nonnull__, __format__(printf, 3, 4))); +void diag_krb5(krb5_context, long, const char *format, ...) + __attribute__((__nonnull__(3), __format__(printf, 3, 4))); /* * Given a Kerberos context and the path to a keytab, retrieve the principal diff --git a/tests/tap/kerberos.sh b/tests/tap/kerberos.sh index e970ae5..13b540d 100644 --- a/tests/tap/kerberos.sh +++ b/tests/tap/kerberos.sh @@ -6,10 +6,11 @@ # Bourne shell. Instead, all private variables are prefixed with "tap_". # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2009, 2010, 2011, 2012 +# Copyright 2016 Russ Allbery +# Copyright 2009-2012 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -29,9 +30,10 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT -# We use test_tmpdir. -. "${SOURCE}/tap/libtap.sh" +. "${C_TAP_SOURCE}/tap/libtap.sh" # Set up Kerberos, including the ticket cache environment variable. Bail out # if not successful, return 0 if successful, and return 1 if Kerberos is not diff --git a/tests/tap/libtap.sh b/tests/tap/libtap.sh index 9731032..38181d9 100644 --- a/tests/tap/libtap.sh +++ b/tests/tap/libtap.sh @@ -7,10 +7,10 @@ # # This file provides a TAP-compatible shell function library useful for # writing test cases. It is part of C TAP Harness, which can be found at -# . +# . # # Written by Russ Allbery -# Copyright 2009, 2010, 2011, 2012 Russ Allbery +# Copyright 2009, 2010, 2011, 2012, 2016 Russ Allbery # Copyright 2006, 2007, 2008, 2013 # The Board of Trustees of the Leland Stanford Junior University # @@ -31,6 +31,8 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT # Print out the number of test cases we expect to run. plan () { @@ -212,32 +214,32 @@ diag () { echo '#' "$@" } -# Search for the given file first in $BUILD and then in $SOURCE and echo the -# path where the file was found, or the empty string if the file wasn't -# found. +# Search for the given file first in $C_TAP_BUILD and then in $C_TAP_SOURCE +# and echo the path where the file was found, or the empty string if the file +# wasn't found. # # This macro uses puts, so don't run it using backticks inside double quotes # or bizarre quoting behavior will happen with Solaris sh. test_file_path () { - if [ -n "$BUILD" ] && [ -f "$BUILD/$1" ] ; then - puts "$BUILD/$1" - elif [ -n "$SOURCE" ] && [ -f "$SOURCE/$1" ] ; then - puts "$SOURCE/$1" + if [ -n "$C_TAP_BUILD" ] && [ -f "$C_TAP_BUILD/$1" ] ; then + puts "$C_TAP_BUILD/$1" + elif [ -n "$C_TAP_SOURCE" ] && [ -f "$C_TAP_SOURCE/$1" ] ; then + puts "$C_TAP_SOURCE/$1" else echo '' fi } -# Create $BUILD/tmp for use by tests for storing temporary files and return -# the path (via standard output). +# Create $C_TAP_BUILD/tmp for use by tests for storing temporary files and +# return the path (via standard output). # # This macro uses puts, so don't run it using backticks inside double quotes # or bizarre quoting behavior will happen with Solaris sh. test_tmpdir () { - if [ -z "$BUILD" ] ; then + if [ -z "$C_TAP_BUILD" ] ; then tap_tmpdir="./tmp" else - tap_tmpdir="$BUILD"/tmp + tap_tmpdir="$C_TAP_BUILD"/tmp fi if [ ! -d "$tap_tmpdir" ] ; then mkdir "$tap_tmpdir" || bail "Error creating $tap_tmpdir" diff --git a/tests/tap/macros.h b/tests/tap/macros.h index 139cff0..32ed815 100644 --- a/tests/tap/macros.h +++ b/tests/tap/macros.h @@ -6,7 +6,7 @@ * everyone can pull them in. * * This file is part of C TAP Harness. The current version plus supporting - * documentation is at . + * documentation is at . * * Copyright 2008, 2012, 2013, 2015 Russ Allbery * @@ -27,6 +27,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_MACROS_H diff --git a/tests/tap/messages.c b/tests/tap/messages.c index 9c28789..a720ec7 100644 --- a/tests/tap/messages.c +++ b/tests/tap/messages.c @@ -6,10 +6,11 @@ * handling. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2002, 2004, 2005, 2015 Russ Allbery - * Copyright 2006, 2007, 2009, 2012, 2014 + * Written by Russ Allbery + * Copyright 2002, 2004-2005, 2015 Russ Allbery + * Copyright 2006-2007, 2009, 2012, 2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -29,6 +30,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include diff --git a/tests/tap/messages.h b/tests/tap/messages.h index 985b9cd..3076113 100644 --- a/tests/tap/messages.h +++ b/tests/tap/messages.h @@ -2,10 +2,11 @@ * Utility functions to test message handling. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * + * Written by Russ Allbery * Copyright 2002 Russ Allbery - * Copyright 2006, 2007, 2009 + * Copyright 2006-2007, 2009 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_MESSAGES_H diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm index 8608e31..807508c 100644 --- a/tests/tap/perl/Test/RRA.pm +++ b/tests/tap/perl/Test/RRA.pm @@ -5,6 +5,8 @@ # by both C packages with Automake and by stand-alone Perl modules. See # Test::RRA::Automake for additional functions specifically for C Automake # distributions. +# +# SPDX-License-Identifier: MIT package Test::RRA; @@ -13,6 +15,7 @@ use strict; use warnings; use Exporter; +use File::Temp; use Test::More; # For Perl 5.006 compatibility. @@ -26,12 +29,56 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(skip_unless_author skip_unless_automated use_prereq); + @EXPORT_OK = qw( + is_file_contents skip_unless_author skip_unless_automated use_prereq + ); # 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 = '5.10'; + $VERSION = '7.02'; +} + +# Compare a string to the contents of a file, similar to the standard is() +# function, but to show the line-based unified diff between them if they +# differ. +# +# $got - The output that we received +# $expected - The path to the file containing the expected output +# $message - The message to use when reporting the test results +# +# Returns: undef +# Throws: Exception on failure to read or write files or run diff +sub is_file_contents { + my ($got, $expected, $message) = @_; + + # If they're equal, this is simple. + open(my $fh, '<', $expected) or BAIL_OUT("Cannot open $expected: $!\n"); + my $data = do { local $/ = undef; <$fh> }; + close($fh) or BAIL_OUT("Cannot close $expected: $!\n"); + if ($got eq $data) { + is($got, $data, $message); + return; + } + + # Otherwise, we show a diff, but only if we have IPC::System::Simple. + eval { require IPC::System::Simple }; + if ($@) { + ok(0, $message); + return; + } + + # 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. + ok(0, $message); + return; } # Skip this test unless author tests are requested. Takes a short description @@ -225,10 +272,14 @@ SOFTWARE. Test::More(3), Test::RRA::Automake(3), Test::RRA::Config(3) This module is maintained in the rra-c-util package. The current version is -available from L. +available from L. The functions to control when tests are run use environment variables defined by the L. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm index c6399ec..804c193 100644 --- a/tests/tap/perl/Test/RRA/Automake.pm +++ b/tests/tap/perl/Test/RRA/Automake.pm @@ -7,8 +7,11 @@ # require closely following the conventions implemented by the rra-c-util # utility collection. # -# All the functions here assume that BUILD and SOURCE are set in the -# environment. This is normally done via the C TAP Harness runtests wrapper. +# All the functions here assume that C_TAP_BUILD and C_TAP_SOURCE are set in +# the environment. This is normally done via the C TAP Harness runtests +# wrapper. +# +# SPDX-License-Identifier: MIT package Test::RRA::Automake; @@ -20,6 +23,7 @@ use warnings; ## no critic (ClassHierarchies::ProhibitExplicitISA) use Exporter; +use File::Find qw(find); use File::Spec; use Test::More; use Test::RRA::Config qw($LIBRARY_PATH); @@ -34,9 +38,9 @@ BEGIN { $PERL_BLIB_ARCH = File::Spec->catdir(qw(perl blib arch)); $PERL_BLIB_LIB = File::Spec->catdir(qw(perl blib lib)); - # If BUILD is set, we can come up with better values. - if (defined($ENV{BUILD})) { - my ($vol, $dirs) = File::Spec->splitpath($ENV{BUILD}, 1); + # If C_TAP_BUILD is set, we can come up with better values. + if (defined($ENV{C_TAP_BUILD})) { + my ($vol, $dirs) = File::Spec->splitpath($ENV{C_TAP_BUILD}, 1); my @dirs = File::Spec->splitdir($dirs); pop(@dirs); $PERL_BLIB_ARCH = File::Spec->catdir(@dirs, qw(perl blib arch)); @@ -57,47 +61,93 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(automake_setup perl_dirs test_file_path test_tmpdir); + @EXPORT_OK = qw( + all_files automake_setup perl_dirs test_file_path test_tmpdir + ); # 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 = '5.10'; + $VERSION = '7.02'; } -# Perl directories to skip globally for perl_dirs. We ignore the perl -# directory if it exists since, in my packages, it is treated as a Perl module -# distribution and has its own standalone test suite. -my @GLOBAL_SKIP = qw(.git _build perl); +# 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); + +# Additional paths to skip when building a list of all files in the +# distribution. This primarily skips build artifacts that aren't interesting +# to any of the tests. These match any path component. +my @FILES_SKIP = qw( + .deps .dirstamp .libs aclocal.m4 config.h config.h.in config.h.in~ config.log + config.status configure +); # The temporary directory created by test_tmpdir, if any. If this is set, # attempt to remove the directory stored here on program exit (but ignore # failure to do so). my $TMPDIR; +# Returns a list of all files in the distribution. +# +# Returns: List of files +sub all_files { + my @files; + + # Turn the skip lists into hashes for ease of querying. + my %skip = map { $_ => 1 } @GLOBAL_SKIP; + my %files_skip = map { $_ => 1 } @FILES_SKIP; + + # Wanted function for find. Prune anything matching either of the skip + # lists, or *.lo files, and then add all regular files to the list. + my $wanted = sub { + my $file = $_; + my $path = $File::Find::name; + $path =~ s{ \A [.]/ }{}xms; + if ($skip{$path} or $files_skip{$file} or $file =~ m{ [.] lo \z }xms) { + $File::Find::prune = 1; + return; + } + if (-f $file) { + push(@files, $path); + } + }; + + # Do the recursive search and return the results. + find($wanted, q{.}); + return @files; +} + # Perform initial test setup for running a Perl test in an Automake package. -# This verifies that BUILD and SOURCE are set and then changes directory to -# the SOURCE directory by default. Sets LD_LIBRARY_PATH if the $LIBRARY_PATH -# configuration option is set. Calls BAIL_OUT if BUILD or SOURCE are missing -# or if anything else fails. +# This verifies that C_TAP_BUILD and C_TAP_SOURCE are set and then changes +# directory to the C_TAP_SOURCE directory by default. Sets LD_LIBRARY_PATH if +# the $LIBRARY_PATH configuration option is set. Calls BAIL_OUT if +# C_TAP_BUILD or C_TAP_SOURCE are missing or if anything else fails. # # $args_ref - Reference to a hash of arguments to configure behavior: -# chdir_build - If set to a true value, changes to BUILD instead of SOURCE +# chdir_build - If set to a true value, changes to C_TAP_BUILD instead of +# C_TAP_SOURCE # # Returns: undef sub automake_setup { my ($args_ref) = @_; - # Bail if BUILD or SOURCE are not set. - if (!$ENV{BUILD}) { - BAIL_OUT('BUILD not defined (run under runtests)'); + # Bail if C_TAP_BUILD or C_TAP_SOURCE are not set. + if (!$ENV{C_TAP_BUILD}) { + BAIL_OUT('C_TAP_BUILD not defined (run under runtests)'); } - if (!$ENV{SOURCE}) { - BAIL_OUT('SOURCE not defined (run under runtests)'); + if (!$ENV{C_TAP_SOURCE}) { + BAIL_OUT('C_TAP_SOURCE not defined (run under runtests)'); } - # BUILD or SOURCE will be the test directory. Change to the parent. - my $start = $args_ref->{chdir_build} ? $ENV{BUILD} : $ENV{SOURCE}; + # C_TAP_BUILD or C_TAP_SOURCE will be the test directory. Change to the + # parent. + my $start; + if ($args_ref->{chdir_build}) { + $start = $ENV{C_TAP_BUILD}; + } else { + $start = $ENV{C_TAP_SOURCE}; + } my ($vol, $dirs) = File::Spec->splitpath($start, 1); my @dirs = File::Spec->splitdir($dirs); pop(@dirs); @@ -116,8 +166,9 @@ sub automake_setup { my $root = File::Spec->catpath($vol, File::Spec->catdir(@dirs), q{}); chdir($root) or BAIL_OUT("cannot chdir to $root: $!"); - # If BUILD is a subdirectory of SOURCE, add it to the global ignore list. - my ($buildvol, $builddirs) = File::Spec->splitpath($ENV{BUILD}, 1); + # If C_TAP_BUILD is a subdirectory of C_TAP_SOURCE, add it to the global + # ignore list. + my ($buildvol, $builddirs) = File::Spec->splitpath($ENV{C_TAP_BUILD}, 1); my @builddirs = File::Spec->splitdir($builddirs); pop(@builddirs); if ($buildvol eq $vol && @builddirs == @dirs + 1) { @@ -162,9 +213,11 @@ sub automake_setup { sub perl_dirs { my ($args_ref) = @_; - # Add the global skip list. + # Add the global skip list. We also ignore the perl directory if it + # exists since, in my packages, it is treated as a Perl module + # distribution and has its own standalone test suite. my @skip = $args_ref->{skip} ? @{ $args_ref->{skip} } : (); - push(@skip, @GLOBAL_SKIP); + push(@skip, @GLOBAL_SKIP, 'perl'); # Separate directories to skip under tests from top-level directories. my @skip_tests = grep { m{ \A tests/ }xms } @skip; @@ -206,9 +259,9 @@ sub perl_dirs { return @dirs; } -# Find a configuration file for the test suite. Searches relative to BUILD -# first and then SOURCE and returns whichever is found first. Calls BAIL_OUT -# if the file could not be found. +# Find a configuration file for the test suite. Searches relative to +# C_TAP_BUILD first and then C_TAP_SOURCE and returns whichever is found +# first. Calls BAIL_OUT if the file could not be found. # # $file - Partial path to the file # @@ -216,7 +269,7 @@ sub perl_dirs { sub test_file_path { my ($file) = @_; BASE: - for my $base ($ENV{BUILD}, $ENV{SOURCE}) { + for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}) { next if !defined($base); if (-f "$base/$file") { return "$base/$file"; @@ -236,11 +289,16 @@ sub test_tmpdir { my $path; # If we already figured out what directory to use, reuse the same path. - # Otherwise, create a directory relative to BUILD if set. + # Otherwise, create a directory relative to C_TAP_BUILD if set. if (defined($TMPDIR)) { $path = $TMPDIR; } else { - my $base = defined($ENV{BUILD}) ? $ENV{BUILD} : File::Spec->curdir; + my $base; + if (defined($ENV{C_TAP_BUILD})) { + $base = $ENV{C_TAP_BUILD}; + } else { + $base = File::Spec->curdir; + } $path = File::Spec->catdir($base, 'tmp'); } @@ -297,11 +355,11 @@ layout of a package that uses rra-c-util and C TAP Harness for the test structure. Loading this module will also add the directories C and -C to the Perl library search path, relative to BUILD if that -environment variable is set. This is harmless for C Automake projects that -don't contain an embedded Perl module, and for those projects that do, this -will allow subsequent C calls to find modules that are built as part of -the package build process. +C to the Perl library search path, relative to C_TAP_BUILD if +that environment variable is set. This is harmless for C Automake projects +that don't contain an embedded Perl module, and for those projects that do, +this will allow subsequent C calls to find modules that are built as part +of the package build process. The automake_setup() function should be called before calling any other functions provided by this module. @@ -314,11 +372,20 @@ BAIL_OUT (from Test::More). =over 4 +=item all_files() + +Returns a list of all "interesting" files in the distribution that a test +suite may want to look at. This excludes various products of the build system, +the build directory if it's under the source directory, and a few other +uninteresting directories like F<.git>. The returned paths will be paths +relative to the root of the package. + =item automake_setup([ARGS]) -Verifies that the BUILD and SOURCE environment variables are set and then -changes directory to the top of the source tree (which is one directory up -from the SOURCE path, since SOURCE points to the top of the tests directory). +Verifies that the C_TAP_BUILD and C_TAP_SOURCE environment variables are set +and then changes directory to the top of the source tree (which is one +directory up from the C_TAP_SOURCE path, since C_TAP_SOURCE points to the top +of the tests directory). If ARGS is given, it should be a reference to a hash of configuration options. Only one option is supported: C. If it is set to a true value, @@ -343,30 +410,46 @@ C that should be skipped. Given FILE, which should be a relative path, locates that file relative to the test directory in either the source or build tree. FILE will be checked for -relative to the environment variable BUILD first, and then relative to SOURCE. -test_file_path() returns the full path to FILE or calls BAIL_OUT if FILE could -not be found. +relative to the environment variable C_TAP_BUILD first, and then relative to +C_TAP_SOURCE. test_file_path() returns the full path to FILE or calls +BAIL_OUT if FILE could not be found. =item test_tmpdir() Create a temporary directory for tests to use for transient files and return -the path to that directory. The directory is created relative to the BUILD -environment variable, which must be set. Permissions on the directory are set -using the current umask. test_tmpdir() returns the full path to the temporary -directory or calls BAIL_OUT if it could not be created. +the path to that directory. The directory is created relative to the +C_TAP_BUILD environment variable, which must be set. Permissions on the +directory are set using the current umask. test_tmpdir() returns the full +path to the temporary directory or calls BAIL_OUT if it could not be created. The directory is automatically removed if possible on program exit. Failure to remove the directory on exit is reported with diag() and otherwise ignored. =back +=head1 ENVIRONMENT + +=over 4 + +=item C_TAP_BUILD + +The root of the tests directory in Automake build directory for this package, +used to find files as documented above. + +=item C_TAP_SOURCE + +The root of the tests directory in the source tree for this package, used to +find files as documented above. + +=back + =head1 AUTHOR Russ Allbery =head1 COPYRIGHT AND LICENSE -Copyright 2014, 2015 Russ Allbery +Copyright 2014, 2015, 2018 Russ Allbery Copyright 2013 The Board of Trustees of the Leland Stanford Junior University @@ -393,9 +476,13 @@ SOFTWARE. Test::More(3), Test::RRA(3), Test::RRA::Config(3) This module is maintained in the rra-c-util package. The current version is -available from L. +available from L. The C TAP Harness test driver and libraries for TAP-based C testing are -available from L. +available from L. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm index a5b0d0d..7cb0916 100644 --- a/tests/tap/perl/Test/RRA/Config.pm +++ b/tests/tap/perl/Test/RRA/Config.pm @@ -4,6 +4,8 @@ # configuration file to store some package-specific data. This module loads # that configuration and provides the namespace for the configuration # settings. +# +# SPDX-License-Identifier: MIT package Test::RRA::Config; @@ -34,16 +36,16 @@ 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 = '5.10'; + $VERSION = '7.02'; } -# If BUILD or SOURCE are set in the environment, look for data/perl.conf under -# those paths for a C Automake package. Otherwise, look in t/data/perl.conf -# for a standalone Perl module or tests/data/perl.conf for Perl tests embedded -# in a larger distribution. Don't use Test::RRA::Automake since it may not -# exist. +# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for +# data/perl.conf under those paths for a C Automake package. Otherwise, look +# in t/data/perl.conf for a standalone Perl module or tests/data/perl.conf for +# Perl tests embedded in a larger distribution. Don't use Test::RRA::Automake +# since it may not exist. our $PATH; -for my $base ($ENV{BUILD}, $ENV{SOURCE}, 't', 'tests') { +for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}, './t', './tests') { next if !defined($base); my $path = "$base/data/perl.conf"; if (-r $path) { @@ -70,7 +72,7 @@ our @STRICT_PREREQ; # Load the configuration. if (!do($PATH)) { my $error = $@ || $! || 'loading file did not return true'; - BAIL_OUT("cannot load data/perl.conf: $error"); + BAIL_OUT("cannot load $PATH: $error"); } 1; @@ -98,10 +100,10 @@ for both C Automake packages and stand-alone Perl modules. Test::RRA::Config looks for a file named F relative to the root of the test directory. That root is taken from the environment variables -BUILD or SOURCE (in that order) if set, which will be the case for C Automake -packages using C TAP Harness. If neither is set, it expects the root of the -test directory to be a directory named F relative to the current directory, -which will be the case for stand-alone Perl modules. +C_TAP_BUILD or C_TAP_SOURCE (in that order) if set, which will be the case for +C Automake packages using C TAP Harness. If neither is set, it expects the +root of the test directory to be a directory named F relative to the +current directory, which will be the case for stand-alone Perl modules. The following variables are supported: @@ -185,6 +187,8 @@ Russ Allbery =head1 COPYRIGHT AND LICENSE +Copyright 2015, 2016 Russ Allbery + Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior University @@ -212,9 +216,13 @@ perlcritic(1), Test::MinimumVersion(3), Test::RRA(3), Test::RRA::Automake(3), Test::Strict(3) This module is maintained in the rra-c-util package. The current version is -available from L. +available from L. The C TAP Harness test driver and libraries for TAP-based C testing are -available from L. +available from L. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: diff --git a/tests/tap/perl/Test/RRA/ModuleVersion.pm b/tests/tap/perl/Test/RRA/ModuleVersion.pm index f02877a..49acac4 100644 --- a/tests/tap/perl/Test/RRA/ModuleVersion.pm +++ b/tests/tap/perl/Test/RRA/ModuleVersion.pm @@ -3,6 +3,8 @@ # This module contains the common code for testing and updating Perl module # versions for consistency within a Perl module distribution and within a # larger package that contains both Perl modules and other code. +# +# SPDX-License-Identifier: MIT package Test::RRA::ModuleVersion; @@ -31,7 +33,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 = '5.10'; + $VERSION = '7.02'; } # A regular expression matching the version string for a module using the @@ -290,6 +292,10 @@ SOFTWARE. Test::More(3), Test::RRA::Config(3) This module is maintained in the rra-c-util package. The current version -is available from L. +is available from L. =cut + +# Local Variables: +# copyright-at-end-flag: t +# End: diff --git a/tests/tap/process.c b/tests/tap/process.c index 8c22324..d9e94d8 100644 --- a/tests/tap/process.c +++ b/tests/tap/process.c @@ -11,11 +11,11 @@ * mkstemp. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2002, 2004, 2005, 2013 Russ Allbery - * Copyright 2009, 2010, 2011, 2013, 2014 + * Copyright 2002, 2004-2005, 2013, 2016-2017 Russ Allbery + * Copyright 2009-2011, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -35,6 +35,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -134,6 +136,8 @@ run_child_function(test_function_type function, void *data, int *status, count = 0; do { ret = read(fds[0], buf + count, buflen - count - 1); + if (SSIZE_MAX - count <= ret) + bail("maximum output size exceeded in run_child_function"); if (ret > 0) count += ret; if (count >= buflen - 1) { @@ -141,7 +145,7 @@ run_child_function(test_function_type function, void *data, int *status, buf = brealloc(buf, buflen); } } while (ret > 0); - buf[count < 0 ? 0 : count] = '\0'; + buf[count] = '\0'; if (waitpid(child, &rval, 0) == (pid_t) -1) sysbail("waitpid failed"); close(fds[0]); @@ -364,7 +368,7 @@ process_stop_all(int success UNUSED, int primary) * Read the PID of a process from a file. This is necessary when running * under fakeroot to get the actual PID of the remctld process. */ -static long +static pid_t read_pidfile(const char *path) { FILE *file; @@ -380,7 +384,7 @@ read_pidfile(const char *path) pid = strtol(buffer, NULL, 10); if (pid <= 0) bail("cannot read PID from %s", path); - return pid; + return (pid_t) pid; } diff --git a/tests/tap/process.h b/tests/tap/process.h index 8137d5d..da21ad3 100644 --- a/tests/tap/process.h +++ b/tests/tap/process.h @@ -2,10 +2,10 @@ * Utility functions for tests that use subprocesses. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2009, 2010, 2013 + * Copyright 2009-2010, 2013 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +25,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_PROCESS_H diff --git a/tests/tap/remctl.sh b/tests/tap/remctl.sh index 0a511a0..e39b88f 100644 --- a/tests/tap/remctl.sh +++ b/tests/tap/remctl.sh @@ -6,9 +6,10 @@ # Bourne shell. Instead, all private variables are prefixed with "tap_". # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery +# Copyright 2016 Russ Allbery # Copyright 2009, 2012 # The Board of Trustees of the Leland Stanford Junior University # @@ -29,6 +30,10 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT + +. "${C_TAP_SOURCE}/tap/libtap.sh" # Start remctld. Takes the path to remctld, which may be found via configure, # and the path to the configuration file. @@ -45,7 +50,7 @@ remctld_start () { ( "$VALGRIND" --log-file=valgrind.%p --leak-check=full "$1" -m \ -p 14373 -s "$tap_principal" -P "$tap_pidfile" -f "$2" -d -S -F \ -k "$tap_keytab" &) - [ -f "$BUILD/data/remctld.pid" ] || sleep 5 + [ -f "$tap_pidfile" ] || sleep 5 else ( "$1" -m -p 14373 -s "$tap_principal" -P "$tap_pidfile" -f "$2" \ -d -S -F -k "$tap_keytab" &) diff --git a/tests/tap/string.c b/tests/tap/string.c index 6ed7e68..71cf571 100644 --- a/tests/tap/string.c +++ b/tests/tap/string.c @@ -5,9 +5,9 @@ * because they rely on additional portability code from rra-c-util. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2011, 2012 Russ Allbery + * Copyright 2011-2012 Russ Allbery * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -26,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include diff --git a/tests/tap/string.h b/tests/tap/string.h index d58f75d..a520210 100644 --- a/tests/tap/string.h +++ b/tests/tap/string.h @@ -5,9 +5,9 @@ * because they rely on additional portability code from rra-c-util. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2011, 2012 Russ Allbery + * Copyright 2011-2012 Russ Allbery * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -26,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef TAP_STRING_H diff --git a/tests/util/messages-krb5-t.c b/tests/util/messages-krb5-t.c index c6de5a5..b22c4cf 100644 --- a/tests/util/messages-krb5-t.c +++ b/tests/util/messages-krb5-t.c @@ -2,10 +2,10 @@ * Test suite for Kerberos error handling routines. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2010, 2011, 2013, 2014 + * Copyright 2010-2011, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +25,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -56,7 +58,7 @@ main(void) /* * Test functions. */ -static void +static void __attribute__((__noreturn__)) test_warn(void *data UNUSED) { krb5_context ctx; @@ -74,7 +76,7 @@ test_warn(void *data UNUSED) exit(0); } -static void +static void __attribute__((__noreturn__)) test_die(void *data UNUSED) { krb5_context ctx; diff --git a/tests/util/messages-t.c b/tests/util/messages-t.c index 1098314..e8a7835 100644 --- a/tests/util/messages-t.c +++ b/tests/util/messages-t.c @@ -2,11 +2,11 @@ * Test suite for error handling routines. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2002, 2004, 2005, 2015 Russ Allbery - * Copyright 2009, 2010, 2011, 2012 + * Copyright 2002, 2004-2005, 2015, 2017 Russ Allbery + * Copyright 2009-2012 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -26,6 +26,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include @@ -46,45 +48,87 @@ /* * Test functions. */ -static void test1(void *data UNUSED) { warn("warning"); } -static void test2(void *data UNUSED) { die("fatal"); } -static void test3(void *data UNUSED) { errno = EPERM; syswarn("permissions"); } -static void test4(void *data UNUSED) { +static void +test1(void *data UNUSED) +{ + warn("warning"); +} + +static void __attribute__((__noreturn__)) +test2(void *data UNUSED) +{ + die("fatal"); +} + +static void +test3(void *data UNUSED) +{ + errno = EPERM; + syswarn("permissions"); +} + +static void __attribute__((__noreturn__)) +test4(void *data UNUSED) +{ errno = EACCES; sysdie("fatal access"); } -static void test5(void *data UNUSED) { + +static void +test5(void *data UNUSED) +{ message_program_name = "test5"; warn("warning"); } -static void test6(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test6(void *data UNUSED) +{ message_program_name = "test6"; die("fatal"); } -static void test7(void *data UNUSED) { + +static void +test7(void *data UNUSED) +{ message_program_name = "test7"; errno = EPERM; syswarn("perms %d", 7); } -static void test8(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test8(void *data UNUSED) +{ message_program_name = "test8"; errno = EACCES; sysdie("%st%s", "fa", "al"); } -static int return10(void) { return 10; } +static int +return10(void) +{ + return 10; +} -static void test9(void *data UNUSED) { +static void __attribute__((__noreturn__)) +test9(void *data UNUSED) +{ message_fatal_cleanup = return10; die("fatal"); } -static void test10(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test10(void *data UNUSED) +{ message_program_name = 0; message_fatal_cleanup = return10; errno = EPERM; sysdie("fatal perm"); } -static void test11(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test11(void *data UNUSED) +{ message_program_name = "test11"; message_fatal_cleanup = return10; errno = EPERM; @@ -93,61 +137,104 @@ static void test11(void *data UNUSED) { } static void __attribute__((__format__(printf, 2, 0))) -log_msg(size_t len, const char *format, va_list args, int error) { +log_msg(size_t len, const char *format, va_list args, int error) +{ fprintf(stderr, "%lu %d ", (unsigned long) len, error); vfprintf(stderr, format, args); fprintf(stderr, "\n"); } -static void test12(void *data UNUSED) { +static void +test12(void *data UNUSED) +{ message_handlers_warn(1, log_msg); warn("warning"); } -static void test13(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test13(void *data UNUSED) +{ message_handlers_die(1, log_msg); die("fatal"); } -static void test14(void *data UNUSED) { + +static void +test14(void *data UNUSED) +{ message_handlers_warn(2, log_msg, log_msg); errno = EPERM; syswarn("warning"); } -static void test15(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +test15(void *data UNUSED) +{ message_handlers_die(2, log_msg, log_msg); message_fatal_cleanup = return10; errno = EPERM; sysdie("fatal"); } -static void test16(void *data UNUSED) { + +static void +test16(void *data UNUSED) +{ message_handlers_warn(2, message_log_stderr, log_msg); message_program_name = "test16"; errno = EPERM; syswarn("warning"); } -static void test17(void *data UNUSED) { notice("notice"); } -static void test18(void *data UNUSED) { + +static void +test17(void *data UNUSED) +{ + notice("notice"); +} + +static void +test18(void *data UNUSED) +{ message_program_name = "test18"; notice("notice"); } -static void test19(void *data UNUSED) { debug("debug"); } -static void test20(void *data UNUSED) { + +static void +test19(void *data UNUSED) +{ + debug("debug"); +} + +static void +test20(void *data UNUSED) +{ message_handlers_notice(1, log_msg); notice("foo"); } -static void test21(void *data UNUSED) { + +static void +test21(void *data UNUSED) +{ message_handlers_debug(1, message_log_stdout); message_program_name = "test23"; debug("baz"); } -static void test22(void *data UNUSED) { + +static void __attribute__((__noreturn__)) +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); notice("second"); diff --git a/tests/util/xmalloc-t b/tests/util/xmalloc-t index af604ed..e73a7c6 100755 --- a/tests/util/xmalloc-t +++ b/tests/util/xmalloc-t @@ -3,11 +3,11 @@ # Test suite for xmalloc and friends. # # The canonical version of this file is maintained in the rra-c-util package, -# which can be found at . +# which can be found at . # # Written by Russ Allbery -# Copyright 2000, 2001, 2006, 2014 Russ Allbery -# Copyright 2008, 2009, 2010, 2012 +# Copyright 2000-2001, 2006, 2014, 2016 Russ Allbery +# Copyright 2008-2010, 2012 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -27,9 +27,11 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +# +# SPDX-License-Identifier: MIT -. "$SOURCE/tap/libtap.sh" -cd "$BUILD/util" +. "$C_TAP_SOURCE/tap/libtap.sh" +cd "$C_TAP_BUILD/util" # Run an xmalloc test. Takes the description, the expectd exit status, the # output, and the arguments. diff --git a/tests/util/xmalloc.c b/tests/util/xmalloc.c index 84ba081..d157bbb 100644 --- a/tests/util/xmalloc.c +++ b/tests/util/xmalloc.c @@ -2,10 +2,10 @@ * Test suite for xmalloc and family. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2000, 2001, 2006 Russ Allbery - * Copyright 2008, 2012, 2013, 2014 + * Copyright 2000-2001, 2006, 2017 Russ Allbery + * Copyright 2008, 2012-2014 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +25,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #line 1 "xmalloc.c" @@ -50,7 +52,7 @@ * A customized error handler for checking xmalloc's support of them. Prints * out the error message and exits with status 1. */ -static void +static void __attribute__((__noreturn__)) test_handler(const char *function, size_t size, const char *file, int line) { die("%s %lu %s %d", function, (unsigned long) size, file, line); @@ -327,7 +329,7 @@ main(int argc, char *argv[]) code = argv[1][0]; if (isupper(code)) { xmalloc_error_handler = test_handler; - code = tolower(code); + code = (unsigned char) tolower(code); } /* @@ -390,9 +392,7 @@ main(int argc, char *argv[]) case 'n': exit(test_strndup(size) ? willfail : 1); case 'a': exit(test_asprintf(size) ? willfail : 1); case 'v': exit(test_vasprintf(size) ? willfail : 1); - default: - die("Unknown mode %c", argv[1][0]); - break; + default: die("Unknown mode %c", argv[1][0]); } exit(1); } diff --git a/util/macros.h b/util/macros.h index 4a773a2..612a88c 100644 --- a/util/macros.h +++ b/util/macros.h @@ -2,17 +2,19 @@ * Some standard helpful macros. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery + * Copyright 2014 Russ Allbery + * Copyright 2008-2011 + * The Board of Trustees of the Leland Stanford Junior University * - * The authors hereby relinquish any claim to any copyright that they may have - * in this work, whether granted under contract or by operation of law or - * international treaty, and hereby commit to the public, at large, that they - * shall not, at any time in the future, seek to enforce any copyright in this - * work against any person or entity, or prevent any person or entity from - * copying, publishing, distributing or creating derivative works of this - * work. + * Copying and distribution of this file, with or without modification, are + * permitted in any medium without royalty provided the copyright notice and + * this notice are preserved. This file is offered as-is, without any + * warranty. + * + * SPDX-License-Identifier: FSFAP */ #ifndef UTIL_MACROS_H diff --git a/util/messages-krb5.c b/util/messages-krb5.c index 961ea1d..a33d77a 100644 --- a/util/messages-krb5.c +++ b/util/messages-krb5.c @@ -6,10 +6,10 @@ * formatted message. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2006, 2007, 2008, 2009, 2010, 2013 + * Copyright 2006-2010, 2013 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -29,6 +29,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #include diff --git a/util/messages-krb5.h b/util/messages-krb5.h index 3fc0862..da96e4c 100644 --- a/util/messages-krb5.h +++ b/util/messages-krb5.h @@ -2,10 +2,10 @@ * Prototypes for error handling for Kerberos. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2006, 2007, 2008, 2009, 2010, 2013 + * Copyright 2006-2010, 2013 * The Board of Trustees of the Leland Stanford Junior University * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,6 +25,8 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT */ #ifndef UTIL_MESSAGES_KRB5_H @@ -44,9 +46,9 @@ BEGIN_DECLS * an error code to get the Kerberos error. */ void die_krb5(krb5_context, krb5_error_code, const char *, ...) - __attribute__((__nonnull__, __noreturn__, __format__(printf, 3, 4))); + __attribute__((__nonnull__(3), __noreturn__, __format__(printf, 3, 4))); void warn_krb5(krb5_context, krb5_error_code, const char *, ...) - __attribute__((__nonnull__, __format__(printf, 3, 4))); + __attribute__((__nonnull__(3), __format__(printf, 3, 4))); /* Undo default visibility change. */ #pragma GCC visibility pop diff --git a/util/messages.c b/util/messages.c index b5c2dba..941a88f 100644 --- a/util/messages.c +++ b/util/messages.c @@ -51,15 +51,14 @@ * va_list, and the applicable errno value (if any). * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * * Written by Russ Allbery - * Copyright 2008, 2009, 2010, 2013 + * Copyright 2015-2016 Russ Allbery + * Copyright 2008-2010, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2004, 2005, 2006 - * by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - * 2002, 2003 by The Internet Software Consortium and Rich Salz + * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994-2003 The Internet Software Consortium and Rich Salz * * This code is derived from software contributed to the Internet Software * Consortium by Rich Salz. @@ -75,6 +74,8 @@ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. + * + * SPDX-License-Identifier: ISC */ #include @@ -238,7 +239,7 @@ message_log_syslog(int pri, size_t len, const char *fmt, va_list args, int err) exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1); } status = vsnprintf(buffer, len + 1, fmt, args); - if (status < 0) { + if (status < 0 || (size_t) status >= len + 1) { warn("failed to format output with vsnprintf in syslog handler"); free(buffer); return; diff --git a/util/messages.h b/util/messages.h index cf91ba7..3620273 100644 --- a/util/messages.h +++ b/util/messages.h @@ -2,14 +2,14 @@ * Prototypes for message and error reporting (possibly fatal). * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2008, 2010, 2013, 2014 + * Written by Russ Allbery + * Copyright 2015 Russ Allbery + * Copyright 2008, 2010, 2013-2014 * The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2004, 2005, 2006 - * by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - * 2002, 2003 by The Internet Software Consortium and Rich Salz + * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994-2003 The Internet Software Consortium and Rich Salz * * This code is derived from software contributed to the Internet Software * Consortium by Rich Salz. @@ -25,6 +25,8 @@ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. + * + * SPDX-License-Identifier: ISC */ #ifndef UTIL_MESSAGES_H diff --git a/util/xmalloc.c b/util/xmalloc.c index 7fb0405..f5cacc3 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -60,15 +60,14 @@ * line number to these functions. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * + * Written by Russ Allbery * Copyright 2015 Russ Allbery - * Copyright 2012, 2013, 2014 + * Copyright 2012-2014 * The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2004, 2005, 2006 - * by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - * 2002, 2003 by The Internet Software Consortium and Rich Salz + * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994-2003 The Internet Software Consortium and Rich Salz * * This code is derived from software contributed to the Internet Software * Consortium by Rich Salz. @@ -84,6 +83,8 @@ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. + * + * SPDX-License-Identifier: ISC */ #include diff --git a/util/xmalloc.h b/util/xmalloc.h index 6aa9b93..61f5ed1 100644 --- a/util/xmalloc.h +++ b/util/xmalloc.h @@ -2,14 +2,13 @@ * Prototypes for malloc routines with failure handling. * * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . + * which can be found at . * - * Copyright 2010, 2012, 2013, 2014 + * Written by Russ Allbery + * Copyright 2010, 2012-2014 * The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2004, 2005, 2006 - * by Internet Systems Consortium, Inc. ("ISC") - * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - * 2002, 2003 by The Internet Software Consortium and Rich Salz + * Copyright 2004-2006 Internet Systems Consortium, Inc. ("ISC") + * Copyright 1991, 1994-2003 The Internet Software Consortium and Rich Salz * * This code is derived from software contributed to the Internet Software * Consortium by Rich Salz. @@ -25,6 +24,8 @@ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. + * + * SPDX-License-Identifier: ISC */ #ifndef UTIL_XMALLOC_H @@ -110,7 +111,7 @@ typedef void (*xmalloc_handler_type)(const char *, size_t, const char *, int); /* The default error handler. */ void xmalloc_fail(const char *, size_t, const char *, int) - __attribute__((__nonnull__)); + __attribute__((__nonnull__, __noreturn__)); /* * Assign to this variable to choose a handler other than the default, which -- cgit v1.2.3