tests/data/perl.conf tests/data/perlcriticrc tests/data/perltidyrc \
tests/data/valgrind.supp tests/data/wordlist \
tests/data/wordlist.cdb tests/data/wordlist.sqlite \
- tests/docs/pod-spelling-t tests/docs/pod-t tests/docs/urls-t \
- tests/perl/critic-t tests/perl/minimum-version-t \
- tests/perl/strict-t tests/tap/libtap.sh tests/tap/perl/Test/RRA.pm \
- tests/tap/perl/Test/RRA/Config.pm \
+ tests/docs/pod-spelling-t tests/docs/pod-t tests/perl/critic-t \
+ tests/perl/minimum-version-t tests/perl/strict-t \
+ tests/style/obsolete-strings-t tests/tap/libtap.sh \
+ tests/tap/perl/Test/RRA.pm tests/tap/perl/Test/RRA/Config.pm \
tests/tap/perl/Test/RRA/Automake.pm tests/tools/heimdal-history-t \
tests/tools/heimdal-strength-t tests/tools/wordlist-cdb-t \
tests/tools/wordlist-sqlite-t tests/tools/wordlist-t \
check-valgrind: $(check_PROGRAMS) tests/data/dictionary.pwd
rm -rf $(abs_top_builddir)/tmp-valgrind
mkdir $(abs_top_builddir)/tmp-valgrind
- env RRA_MAINTAINER_TESTS= valgrind --leak-check=full \
+ env valgrind --leak-check=full \
--show-reachable=yes --trace-children=yes \
--log-file=$(abs_top_builddir)/tmp-valgrind/log.%p \
--suppressions=$(abs_top_srcdir)/tests/data/valgrind.supp \
--without-cracklib to configure. This makes the code a bit simpler
and lighter if you don't intend to ever use the CrackLib support.
+ Update to rra-c-util 8.2:
+
+ * Implement explicit_bzero with memset if it is not available.
+ * Reformat all C source using clang-format 10.
+ * Work around Test::Strict not skipping .git directories.
+ * Fix warnings with perltidy 20190601 and Perl::Critic 1.134.
+ * Improve check for obsolete strings.
+ * Use a more standard all-permissive license.
+ * Add SPDX-License-Identifier headers to all substantial source files.
+ * Skip more build system files when running the test suite.
+ * Fix warnings with Clang 10, GCC 10, and the Clang static analyzer.
+ * Exclude more valgrind false positives with Kerberos libraries.
+
+ Update to C TAP Harness 4.7:
+
+ * Fix warnings with GCC 10.
+ * Reformat all C source using clang-format 10.
+ * Fixed malloc error checking in bstrndup.
+ * Add support for valgrind testing via test list options.
+ * Report test failures as left and right, not wanted and seen.
+ * Fix is_string comparisons involving NULL pointers and "(null)".
+ * Add SPDX-License-Identifier headers to all substantial source files.
+
krb5-strength 3.1 (2016-12-25)
A new configuration option, cracklib_maxlen, can be set to skip
dnl Process this file with autoconf to produce a configure script.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-dnl Copyright 2016 Russ Allbery <eagle@eyrie.org>
-dnl Copyright 2006, 2007, 2009, 2010, 2012, 2013, 2014
+dnl Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
+dnl Copyright 2006-2007, 2009-2010, 2012-2014
dnl The Board of Trustees of the Leland Stanford Junior University
dnl
dnl See LICENSE for licensing terms.
AC_CHECK_FUNCS([krb5_get_init_creds_opt_free],
[RRA_FUNC_KRB5_GET_INIT_CREDS_OPT_FREE_ARGS])
AC_CHECK_DECLS([krb5_kt_free_entry], [], [], [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])
AC_CHECK_HEADERS([kadm5/kadm5-pwcheck.h kadm5/kadm5_err.h], [], [],
[RRA_INCLUDES_KRB5])
dnl Checks for basic C functionality.
AC_HEADER_STDBOOL
-AC_CHECK_HEADERS([sys/bittypes.h sys/select.h sys/time.h syslog.h])
+AC_CHECK_HEADERS([strings.h sys/bittypes.h sys/select.h sys/time.h syslog.h])
AC_CHECK_DECLS([snprintf, vsnprintf])
RRA_C_C99_VAMACROS
RRA_C_GNU_VAMACROS
AC_CHECK_TYPES([ssize_t], [], [],
[#include <sys/types.h>])
RRA_FUNC_SNPRINTF
-AC_CHECK_FUNCS([setrlimit])
+AC_CHECK_FUNCS([explicit_bzero setrlimit])
AC_REPLACE_FUNCS([asprintf mkstemp reallocarray strndup])
dnl Write out the results.
* Changed the type of some variables to size_t to avoid truncation.
* Forced locale in mkdict to avoid problems with non-C-locale sort.
* Added a warning to packer if processing out-of-order words.
+ * Added cast of CRACK_TOLOWER and CRACK_TOUPPER to char.
+ * Added missing break to RULE_MFIRST "(" and RULE_MLAST ")" handling.
See the leading comments in each source file for a more detailed timeline
and list of changes.
* - Fix int8, int16, and int32 definitions.
* 2013-10-01 Russ Allbery <eagle@eyrie.org>
* - Set hidden visibility on all symbols by default.
+ * 2020-05-16 Russ Allbery <eagle@eyrie.org>
+ * - Cast CRACK_TOLOWER and CRACK_TOUPPER to char.
*/
#include <config.h>
/* Undo default visibility change. */
#pragma GCC visibility pop
-#define CRACK_TOLOWER(a) (isupper(a)?tolower(a):(a))
-#define CRACK_TOUPPER(a) (islower(a)?toupper(a):(a))
+#define CRACK_TOLOWER(a) ((char)(isupper(a)?tolower(a):(a)))
+#define CRACK_TOUPPER(a) ((char)(islower(a)?toupper(a):(a)))
#define STRCMP(a,b) strcmp((a),(b))
static int
Suffix(const char *myword, const char *suffix)
{
- register int i;
- register int j;
+ register size_t i;
+ register size_t j;
i = strlen(myword);
j = strlen(suffix);
char *
Reverse(const char *str)
{
- register int i;
- register int j;
+ register size_t i;
+ register size_t j;
static char area[STRINGSIZE];
j = i = strlen(str);
while (*str)
static char *
Pluralise(const char *string)
{
- register int length;
+ register size_t length;
static char area[STRINGSIZE];
length = strlen(string);
strcpy(area, string);
char *
Mangle(const char *input, const char *control)
{
- int limit, min_to_shift;
- register int j;
+ int limit;
+ size_t min_to_shift;
+ register size_t j;
const char *ptr;
static char area[STRINGSIZE * 2] = "";
char area2[STRINGSIZE * 2] = "";
}
}
}
+ break;
+
case RULE_MLAST:
if (!ptr[1] || (ptr[1] == RULE_CLASS && !ptr[2]))
{
}
}
}
+ break;
default:
Debug(1, "Mangle: unknown command %c in %s\n", *ptr, control);
dnl The canonical version of this file is maintained in the rra-c-util
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
-dnl Copyright 2016 Russ Allbery <eagle@eyrie.org>
+dnl Copyright 2016-2020 Russ Allbery <eagle@eyrie.org>
dnl Copyright 2006, 2009, 2016
dnl by Internet Systems Consortium, Inc. ("ISC")
dnl
-dnl Permission to use, copy, modify, and distribute this software for any
+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 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], [-=], [__])])
+[translit([rra_cv_compiler_c_$1], [-=+], [___])])
-dnl Check whether a given flag is supported by the complier.
+dnl Check whether a given flag is supported by the compiler.
AC_DEFUN([RRA_PROG_CC_FLAG],
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if $CC supports $1])
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 warnings that can't be turned on due to other
+dnl of warnings. Desirable CC warnings that can't be turned on due to other
dnl problems:
dnl
-dnl -Wconversion http://bugs.debian.org/488884 (htons warnings)
-dnl -Wsign-conversion Too much noise from ssize_t and flag variables
+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 6.1.0 (2016-09-25). -D_FORTIFY_SOURCE=2 enables
+dnl Last checked against gcc 9.2.1 (2019-09-01). -D_FORTIFY_SOURCE=2 enables
dnl warn_unused_result attribute markings on glibc functions on Linux, which
dnl catches a few more issues. Add -O2 because gcc won't find some warnings
dnl without optimization turned on.
dnl
-dnl The warnings here are listed in the same order they're listed in the
-dnl "Preprocessor Options" and "Warning Options" chapters of the GCC manual.
+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],
AS_IF([test x"$CLANG" = xyes],
[WARNINGS_CFLAGS="-Werror"
m4_foreach_w([flag],
- [-Weverything -Wno-padded],
+ [-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 -Wcomments -Wendif-labels -Wall
- -Wextra -Wformat=2 -Wformat-signedness -Wnull-dereference -Winit-self
- -Wswitch-enum -Wuninitialized -Wstrict-overflow=5
- -Wmissing-format-attribute -Wduplicated-cond -Wtrampolines
- -Wfloat-equal -Wdeclaration-after-statement -Wshadow -Wpointer-arith
- -Wbad-function-cast -Wcast-align -Wwrite-strings -Wdate-time
- -Wjump-misses-init -Wfloat-conversion -Wlogical-op
+ [-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
- -Wnormalized=nfc -Wpacked -Wredundant-decls -Wnested-externs -Winline
- -Wvla],
+ -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])])
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], [[
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-dnl Copyright 2011, 2012
+dnl Copyright 2018 Russ Allbery <eagle@eyrie.org>
+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,
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],
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-dnl Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014
+dnl Copyright 2018 Russ Allbery <eagle@eyrie.org>
+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], [:])
dnl be found.
AC_DEFUN([_RRA_LIB_KRB5_REDUCED],
[RRA_LIB_KRB5_SWITCH
- AC_CHECK_LIB([krb5], [krb5_init_context], [KRB5_LIBS="-lkrb5"],
+ AC_CHECK_LIB([krb5], [krb5_init_context],
+ [KRB5_LIBS="-lkrb5"
+ LIBS="$KRB5_LIBS $LIBS"
+ _RRA_LIB_KRB5_CHECK_HEADER_KRB5
+ AC_CHECK_FUNCS([krb5_get_error_message],
+ [AC_CHECK_FUNCS([krb5_free_error_message])],
+ [AC_CHECK_FUNCS([krb5_get_error_string], [],
+ [AC_CHECK_FUNCS([krb5_get_err_txt], [],
+ [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
+ [KRB5_LIBS="$KRB5_LIBS -lksvc"
+ AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1])
+ AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
+ [RRA_INCLUDES_KRB5])],
+ [AC_CHECK_LIB([com_err], [com_err],
+ [KRB5_LIBS="$KRB5_LIBS -lcom_err"],
+ [AS_IF([test x"$1" = xtrue],
+ [AC_MSG_ERROR([cannot find usable com_err library])],
+ [KRB5_LIBS=""])])
+ _RRA_LIB_KRB5_CHECK_HEADER_COM_ERR])])])])],
[AS_IF([test x"$1" = xtrue],
[AC_MSG_ERROR([cannot find usable Kerberos library])])])
- LIBS="$KRB5_LIBS $LIBS"
- _RRA_LIB_KRB5_CHECK_HEADER_KRB5
- AC_CHECK_FUNCS([krb5_get_error_message],
- [AC_CHECK_FUNCS([krb5_free_error_message])],
- [AC_CHECK_FUNCS([krb5_get_error_string], [],
- [AC_CHECK_FUNCS([krb5_get_err_txt], [],
- [AC_CHECK_LIB([ksvc], [krb5_svc_get_msg],
- [KRB5_LIBS="$KRB5_LIBS -lksvc"
- AC_DEFINE([HAVE_KRB5_SVC_GET_MSG], [1])
- AC_CHECK_HEADERS([ibm_svc/krb5_svc.h], [], [],
- [RRA_INCLUDES_KRB5])],
- [AC_CHECK_LIB([com_err], [com_err],
- [KRB5_LIBS="$KRB5_LIBS -lcom_err"],
- [AS_IF([test x"$1" = xtrue],
- [AC_MSG_ERROR([cannot find usable com_err library])],
- [KRB5_LIBS=""])])
- _RRA_LIB_KRB5_CHECK_HEADER_COM_ERR])])])])
RRA_LIB_KRB5_RESTORE])
dnl Does the appropriate library checks for Kerberos linkage when we don't
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-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
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
+dnl Copyright 2018 Russ Allbery <eagle@eyrie.org>
dnl Copyright 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 Add the library flags to the default compiler flags and then remove them.
dnl
AC_SUBST([$1][_LDFLAGS])
AC_SUBST([$1][_LIBS])])
+dnl Unset all of the variables used by a library probe. Used with the
+dnl _OPTIONAL versions of header probes when a header or library wasn't found
+dnl and therefore the library isn't usable.
+AC_DEFUN([RRA_LIB_HELPER_VAR_CLEAR],
+[$1[]_CPPFLAGS=
+ $1[]_LDFLAGS=
+ $1[]_LIBS=])
+
dnl Handles --with options for a non-optional library. First argument is the
dnl base for the switch names. Second argument is the short description.
dnl Third argument is the variable prefix. The variables set are used by
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-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
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-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], [[
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 libevent flags. Used as a wrapper, with
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 TinyCDB flags. Used as a wrapper, with
dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
dnl
dnl Written by Russ Allbery <eagle@eyrie.org>
-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 <stdio.h>
int status;
*found = false;
- status = cdb_find(&data->cdb, password, strlen(password));
+ status = cdb_find(&data->cdb, password, (unsigned int) strlen(password));
if (status < 0)
return strength_error_system(ctx, "cannot query CDB database");
else {
krb5_free_default_realm(ctx, realm);
return NULL;
}
- realm_data->length = strlen(realm);
+ realm_data->length = (unsigned int) strlen(realm);
krb5_free_default_realm(ctx, realm);
return realm_data;
}
const char *password)
{
krb5_error_code code;
- size_t length, prefix_length, suffix_length;
+ size_t length;
+ int prefix_length, suffix_length;
char *prefix = NULL;
char *drowssap = NULL;
bool found = false;
* Determine the length of the prefix and suffix into which we'll divide
* the string. Passwords shorter than two characters cannot be
* meaningfully checked using this method and cause boundary condition
- * problems.
+ * problems. Passwords longer than INT_MAX cannot be passed to the SQLite
+ * library.
*/
length = strlen(password);
- if (length < 2)
+ if (length < 2 || length > INT_MAX)
return 0;
- prefix_length = length / 2;
- suffix_length = length - prefix_length;
+ prefix_length = (int) length / 2;
+ suffix_length = (int) length - prefix_length;
/* Obtain the reversed password, used for suffix checks. */
drowssap = reverse_string(password);
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2006, 2015 Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * 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 <portable/macros.h>
/* 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)
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 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
*/
#ifndef PORTABLE_KADMIN_H
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015-2016, 2018 Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
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);
--- /dev/null
+/*
+ * 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 <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Copyright 1985-2005 by the Massachusetts Institute of Technology.
+ * For license information, see the end of this file.
+ */
+
+#include <config.h>
+
+#include <krb5.h>
+#ifdef HAVE_K5PROFILE_H
+# include <k5profile.h>
+#endif
+#ifdef HAVE_PROFILE_H
+# include <profile.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+
+ /*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 = <boolean>
+ * }
+ * }
+ */
+
+ 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 = <boolean>
+ * }
+ */
+
+ 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 = <boolean>
+ */
+
+ 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 = <boolean>
+ */
+
+ 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 MERCHANTABILITY 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.
+ */
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015, 2017, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
/* 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
+
/*
* MIT-specific. The Heimdal documentation says to use free(), but that
* doesn't actually make sense since the memory is allocated inside the
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2015 Russ Allbery <eagle@eyrie.org>
+ * 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
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
errno = ENOMEM;
return NULL;
}
+
+ /* Avoid a zero-size allocation. */
+ if (nmemb == 0 || size == 0) {
+ nmemb = 1;
+ size = 1;
+ }
return realloc(ptr, nmemb * size);
}
# define vsnprintf test_vsnprintf
#endif
+/*
+ * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
+ * could you use the __format__ form of the attributes, which is what we use
+ * (to avoid confusion with other macros).
+ */
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __attribute__(spec) /* empty */
+# endif
+#endif
+
+/*
+ * Older Clang doesn't support __attribute__((fallthrough)) properly and
+ * complains about the empty statement that it is decorating. Suppress that
+ * warning. Also suppress warnings about unknown attributes to handle older
+ * Clang versions.
+ */
+#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__))
+# pragma GCC diagnostic ignored "-Wattributes"
+# pragma GCC diagnostic ignored "-Wmissing-declarations"
+#endif
+
+/* Specific to rra-c-util, but only when debugging is enabled. */
+#ifdef DEBUG_SNPRINTF
+# include <util/messages.h>
+#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.
*/
/**************************************************************
* probably requires libm on most operating systems. Don't yet
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
* was pretty badly broken, it just wasn't being exercised in ways
- * which showed it, so that's been fixed. Also, formated the code
+ * which showed it, so that's been fixed. Also, formatted the code
* to mutt conventions, and removed dead code left over from the
* original. Also, there is now a builtin-test, just compile with:
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
* 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 <hniksic@arsdigita.com> 2000-11-04
+ * Hrvoje Niksic <hniksic@xemacs.org> 2000-11-04
+ * include <config.h> instead of "config.h".
+ * moved TEST_SNPRINTF stuff out of HAVE_SNPRINTF ifdef.
* include <stdio.h> 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 <hniksic@xemacs.org> 2005-04-15
* use the PARAMS macro to handle prototypes.
/* varargs declarations: */
#include <stdarg.h>
-#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
break;
case 'X':
flags |= DP_F_UP;
+ __attribute__((fallthrough));
+ /* fall through */
case 'x':
flags |= DP_F_UNSIGNED;
if (cflags == DP_C_SHORT)
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;
+ __attribute__((fallthrough));
+ /* fall through */
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;
+ __attribute__((fallthrough));
+ /* fall through */
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 *);
{
short int *num;
num = va_arg (args, short int *);
- *num = currlen;
+ *num = (short) currlen;
}
else if (cflags == DP_C_LONG)
{
{
int *num;
num = va_arg (args, int *);
- *num = currlen;
+ *num = (int) currlen;
}
break;
case '%':
}
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);*/
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;
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 */
return result;
}
-static LLONG pow10_int (int exp)
+static LLONG pow10_int (unsigned int exp)
{
LDOUBLE result = 1;
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;
if (intpart != 0)
{
/* For each digit of INTPART, print one less fractional digit. */
- LLONG temp = intpart;
+ LLONG temp;
for (temp = intpart; temp != 0; temp /= 10)
--max;
if (max < 0)
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;
}
}
}
#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--;
/* 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))
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;
}
num++;
}
printf ("%d tests failed out of %d.\n", fail, num);
+ return 0;
}
-#endif /* SNPRINTF_TEST */
+#endif /* TEST_SNPRINTF */
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * 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
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 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
*/
#include <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014, 2016, 2018, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
# endif
#endif
+/*
+ * If explicit_bzero is not available, fall back on memset. This does NOT
+ * provide any of the security guarantees of explicit_bzero and will probably
+ * be optimized away by the compiler. It just ensures that code will compile
+ * and function on systems without explicit_bzero.
+ */
+#if !HAVE_EXPLICIT_BZERO
+# define explicit_bzero(s, n) memset((s), 0, (n))
+#endif
+
BEGIN_DECLS
/* Default to a hidden visibility for all portability functions. */
#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 *);
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
docs/pod
docs/pod-spelling
-docs/urls
plugin/heimdal
plugin/mit
perl/critic
portable/mkstemp
portable/snprintf
portable/strndup
+style/obsolete-strings
tools/heimdal-history
tools/heimdal-strength
tools/wordlist
# for packages that run perlcritic tests automatically during the build for
# reproducible test results.
#
-# This file has been updated to match perlcritic 1.118.
+# This file has been updated to match perlcritic 1.134.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2011, 2012, 2013
+# Copyright 2018-2019 Russ Allbery <eagle@eyrie.org>
+# Copyright 2011-2013
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
# 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
severity = 1
verbose = %f:%l:%c: [%p] %m (%e, Severity: %s)\n
# This is handled with a separate test case that uses Test::Spelling.
[-Documentation::PodSpelling]
-# Pod::Man and Pod::Text fixed this bug years ago. I know, I maintain them.
-[-Documentation::RequirePodLinksIncludeText]
-
# The POD sections Perl::Critic wants are incompatible with the POD template
# from perlpodstyle, which is what I use for my POD documentation.
[-Documentation::RequirePodSections]
# off.
[-RegularExpressions::ProhibitComplexRegexes]
+# Produces false positives currently with postfix dereferencing (introduced in
+# Perl 5.20). See https://github.com/Perl-Critic/Perl-Critic/issues/578.
+[-References::ProhibitDoubleSigils]
+
# I generally don't want to require Readonly as a prerequisite for all my Perl
# modules.
[-ValuesAndExpressions::ProhibitConstantPragma]
[ValuesAndExpressions::RequireNumberSeparators]
min_value = 100000
+# IO::Uncompress::Gunzip puts the error message in a package variable.
# Text::Wrap has a broken interface that requires use of package variables.
[Variables::ProhibitPackageVars]
-add_packages = Text::Wrap
+add_packages = IO::Uncompress::Gunzip Text::Wrap
# use English was one of the worst ideas in the history of Perl. It makes the
# code slightly more readable for amateurs at the cost of confusing
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
+#
+# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2012-2013
+# The Board of Trustees of the Leland Stanford Junior University
+#
+# 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
-bbao # put line breaks before any operator
-nbbc # don't force blank lines before comments (bad for else blocks)
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2011, 2012, 2013, 2014
+# Copyright 2017-2018 Russ Allbery <eagle@eyrie.org>
+# Copyright 2011-2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a
# 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
{
dlopen-dlerror
fun:calloc
fun:_dlerror_run
}
+{
+ fakeroot-msgsnd
+ Memcheck:Param
+ msgsnd(msgp->mtext)
+ fun:msgsnd
+ fun:send_fakem
+ fun:send_get_fakem
+ obj:*/libfakeroot-sysv.so
+}
+{
+ heimdal-base-once
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:heim_base_once_f
+}
{
heimdal-gss-config
Memcheck:Leak
...
fun:krb5_gss_save_error_string
}
+{
+ mit-gss-mechs
+ Memcheck:Leak
+ fun:glob
+ fun:loadConfigFiles
+ fun:updateMechList
+ fun:build_mechSet
+ fun:gss_indicate_mechs
+}
+{
+ mit-kadmin-ovku-error
+ Memcheck:Leak
+ fun:*alloc*
+ fun:initialize_ovku_error_table_r
+}
+{
+ mit-krb5-changepw
+ Memcheck:Leak
+ fun:*alloc
+ fun:change_set_password
+ fun:krb5_change_password
+ fun:krb5_get_init_creds_password
+}
{
mit-krb5-pkinit-openssl-init
Memcheck:Leak
...
fun:krb5_preauth_request_context_init
}
+{
+ mit-krb5-pkinit-openssl-request-2
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:k5_preauth_request_context_init
+}
{
mit-krb5-plugin-dirs
Memcheck:Leak
fun:strdup
fun:register_module.isra.1
}
+{
+ mit-krb5-preauth-init
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:k5_init_preauth_context
+}
+{
+ mit-krb5-preauth-init
+ Memcheck:Leak
+ fun:strdup
+ fun:add_to_list
+ fun:profile_get_values
+ ...
+ fun:clpreauth_prep_questions
+}
+{
+ mit-krb5-preauth-init-2
+ Memcheck:Leak
+ fun:*alloc
+ fun:init_list
+ fun:profile_get_values
+ ...
+ fun:clpreauth_prep_questions
+}
+{
+ mit-krb5-profile
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:profile_open_file
+}
{
portable-setenv
Memcheck:Leak
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016, 2019 Russ Allbery <eagle@eyrie.org>
+# 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
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_author use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
+use Test::More;
+
# Only run this test for the module author since the required stopwords are
# too sensitive to the exact spell-checking program and dictionary.
skip_unless_author('Spelling tests');
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016, 2019 Russ Allbery <eagle@eyrie.org>
+# 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
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
+use Test::More;
+
# Skip this test for normal user installs, since we normally pre-generate all
# of the documentation and the end user doesn't care.
skip_unless_automated('POD syntax tests');
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016, 2019 Russ Allbery <eagle@eyrie.org>
+# 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
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use File::Spec;
-use Test::More;
use Test::RRA qw(skip_unless_author use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs test_file_path);
use Test::RRA::Config qw(@CRITIC_IGNORE);
+use File::Spec;
+use Test::More;
+
# Skip tests unless we're running author tests since this test is too
# sensitive to the exact version of Perl::Critic to be generally useful.
skip_unless_author('Coding style tests');
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016, 2019-2020 Russ Allbery <eagle@eyrie.org>
+# 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
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
use Test::RRA::Config qw($MINIMUM_VERSION %MINIMUM_VERSION);
+use Test::More;
+
# Skip for normal user installs since this doesn't affect functionality.
skip_unless_automated('Minimum version tests');
automake_setup();
# For each exception case in %MINIMUM_VERSION, check the files that should
-# have that minium version. Sort for reproducible test order. Also
+# have that minimum version. Sort for reproducible test order. Also
# accumulate the list of directories we've already tested.
my @tested;
for my $version (sort keys %MINIMUM_VERSION) {
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2012, 2013, 2014
+# Copyright 2016, 2019 Russ Allbery <eagle@eyrie.org>
+# 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
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(skip_unless_automated use_prereq);
use Test::RRA::Automake qw(automake_setup perl_dirs);
use Test::RRA::Config qw(@STRICT_IGNORE @STRICT_PREREQ);
+use Test::More;
+
# Skip for normal user installs since this doesn't affect functionality.
skip_unless_automated('Strictness tests');
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014, 2018 Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
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;
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014 Russ Allbery <eagle@eyrie.org>
+ * 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 <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010
+ * Copyright 2000-2006, 2018-2020 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2010
* The Board of Trustees of the Leland Stanford Junior University
* Copyright 1995 Patrick Powell
* Copyright 2001 Hrvoje Niksic
* 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 <config.h>
static const char string[] = "abcdefghijklmnopqrstuvwxyz0123456789";
+/* clang-format off */
+
static const char *const fp_formats[] = {
- "%-1.5f", "%1.5f", "%31.9f", "%10.5f", "% 10.5f", "%+22.9f", "%+4.9f",
- "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f", "%f",
-
-/* %e and %g formats aren't really implemented yet. */
-#if 0
- "%-1.5e", "%1.5e", "%31.9e", "%10.5e", "% 10.5e", "%+22.9e",
- "%+4.9e", "%01.3e", "%3.1e", "%3.2e", "%.0e", "%.1e",
- "%e",
- "%-1.5g", "%1.5g", "%31.9g", "%10.5g", "% 10.5g", "%+22.9g",
- "%+4.9g", "%01.3g", "%3.1g", "%3.2g", "%.0g", "%.1g",
- "%g",
-#endif
- NULL};
+ "%-1.5f", "%1.5f", "%31.6f", "%10.5f", "% 10.5f", "%+22.6f",
+ "%+4.6f", "%01.3f", "%3.1f", "%3.2f", "%.0f", "%.1f",
+ "%f",
+ NULL
+};
static const char *const int_formats[] = {
- "%-1.5d", "%1.5d", "%31.9d", "%5.5d", "%10.5d", "% 10.5d",
- "%+22.30d", "%01.3d", "%4d", "%d", "%ld", NULL};
+ "%-1.5d", "%1.5d", "%31.9d", "%5.5d", "%10.5d", "% 10.5d",
+ "%+22.30d", "%01.3d", "%4d", "%d", "%ld", NULL
+};
static const char *const uint_formats[] = {
- "%-1.5lu", "%1.5lu", "%31.9lu", "%5.5lu", "%10.5lu",
- "% 10.5lu", "%+6.30lu", "%01.3lu", "%4lu", "%lu",
- "%4lx", "%4lX", "%01.3lx", "%1lo", NULL};
+ "%-1.5lu", "%1.5lu", "%31.9lu", "%5.5lu", "%10.5lu", "% 10.5lu",
+ "%+6.30lu", "%01.3lu", "%4lu", "%lu", "%4lx", "%4lX",
+ "%01.3lx", "%1lo", NULL
+};
static const char *const llong_formats[] = {
- "%lld", "%-1.5lld", "%1.5lld", "%123.9lld", "%5.5lld", "%10.5lld",
- "% 10.5lld", "%+22.33lld", "%01.3lld", "%4lld", NULL};
+ "%lld", "%-1.5lld", "%1.5lld", "%123.9lld", "%5.5lld",
+ "%10.5lld", "% 10.5lld", "%+22.33lld", "%01.3lld", "%4lld",
+ NULL
+};
static const char *const ullong_formats[] = {
- "%llu", "%-1.5llu", "%1.5llu", "%123.9llu", "%5.5llu",
- "%10.5llu", "% 10.5llu", "%+22.33llu", "%01.3llu", "%4llu",
- "%llx", "%llo", NULL};
-
-static const double fp_nums[] = {-1.5, 134.21, 91340.2, 341.1234, 0203.9,
- 0.96, 0.996, 0.9996, 1.996, 4.136,
- 0.1, 0.01, 0.001, 10.1, 0};
-static long int_nums[] = {-1, 134, 91340, 341, 0203, 0};
+ "%llu", "%-1.5llu", "%1.5llu", "%123.9llu", "%5.5llu",
+ "%10.5llu", "% 10.5llu", "%+22.33llu", "%01.3llu", "%4llu",
+ "%llx", "%llo", NULL
+};
+
+static const double fp_nums[] = {
+ -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, 0.9996, 1.996,
+ 4.136, 0.1, 0.01, 0.001, 10.1, 0
+};
+static long int_nums[] = {
+ -1, 134, 91340, 341, 0203, 0
+};
static unsigned long uint_nums[] = {
- (unsigned long) -1, 134, 91340, 341, 0203, 0};
-static long long llong_nums[] = {~(long long) 0, /* All-1 bit pattern. */
- (~(unsigned long long) 0)
- >> 1, /* Largest signed long long. */
- -150,
- 134,
- 91340,
- 341,
- 0};
+ (unsigned long) -1, 134, 91340, 341, 0203, 0
+};
+static long long llong_nums[] = {
+ ~(long long) 0, /* All-1 bit pattern. */
+ (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
+ -150, 134, 91340, 341,
+ 0
+};
static unsigned long long ullong_nums[] = {
- ~(unsigned long long) 0, /* All-1 bit pattern. */
- (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
- 134,
- 91340,
- 341,
- 0};
+ ~(unsigned long long) 0, /* All-1 bit pattern. */
+ (~(unsigned long long) 0) >> 1, /* Largest signed long long. */
+ 134, 91340, 341,
+ 0
+};
+
+/* clang-format on */
static void
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++) {
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2018 Russ Allbery <eagle@eyrie.org>
+ * Copyright 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
*/
#include <config.h>
main(void)
{
char buffer[3];
- char *result = NULL;
+ char *result;
plan(7);
/*
* 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 <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
+ *
+ * Copyright 2000-2001, 2004, 2006-2019 Russ Allbery <eagle@eyrie.org>
+ *
+ * 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 <build-dir>] [-s <source-dir>] -l <test-list>
* runtests -o [-h] [-b <build-dir>] [-s <source-dir>] <test>
*
* 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
* 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 <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
- *
- * Copyright 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
- * 2014, 2015, 2016 Russ Allbery <eagle@eyrie.org>
- *
- * 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(). */
/* 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. */
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. */
-------------------------- -------------- ---- ---- ------------------------";
/* Include the file name and line number in malloc failures. */
-#define xcalloc(n, size) x_calloc((n), (size), __FILE__, __LINE__)
-#define xmalloc(size) x_malloc((size), __FILE__, __LINE__)
-#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
-#define xreallocarray(p, n, size) \
- x_reallocarray((p), (n), (size), __FILE__, __LINE__)
+#define xcalloc(n, type) \
+ ((type *) x_calloc((n), sizeof(type), __FILE__, __LINE__))
+#define xmalloc(size) ((char *) x_malloc((size), __FILE__, __LINE__))
+#define xstrdup(p) x_strdup((p), __FILE__, __LINE__)
+#define xstrndup(p, size) x_strndup((p), (size), __FILE__, __LINE__)
+#define xreallocarray(p, n, type) \
+ ((type *) x_reallocarray((p), (n), sizeof(type), __FILE__, __LINE__))
/*
* __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
#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)
__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);
+}
/*
static void *
x_reallocarray(void *p, size_t n, size_t size, const char *file, int line)
{
+ n = (n > 0) ? n : 1;
+ size = (size > 0) ? size : 1;
+
if (n > 0 && UINT_MAX / n <= size)
sysdie("realloc too large at %s line %d", file, line);
p = realloc(p, n * size);
size_t len;
len = strlen(s) + 1;
- p = malloc(len);
+ p = (char *) malloc(len);
if (p == NULL)
sysdie("failed to strdup %lu bytes at %s line %d", (unsigned long) len,
file, line);
}
+/*
+ * 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 = (char *) 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.
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;
}
}
+/*
+ * 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;
}
/* 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:
*/
if (ts->allocated == 0) {
s = (n > 32) ? n : 32;
- ts->results = xcalloc(s, sizeof(enum test_status));
+ ts->results = xcalloc(s, enum test_status);
} else {
s = (n > ts->allocated + 1024) ? n : ts->allocated + 1024;
- ts->results = xreallocarray(ts->results, s, sizeof(enum test_status));
+ ts->results = xreallocarray(ts->results, s, enum test_status);
}
/* Set the results for the newly-allocated test array. */
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");
struct testset *ts;
unsigned int chars;
unsigned long i, first, last, total;
+ double failed;
puts(header);
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, ts->skipped);
+ total, total ? (failed * 100.0) / (double) total : 0,
+ ts->skipped);
if (WIFEXITED(ts->status))
printf("%4d ", WEXITSTATUS(ts->status));
else
}
+/*
+ * 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;
+ } else if (strncmp(p, "valgrind", end - p) == 0) {
+ valgrind = getenv("C_TAP_VALGRIND");
+ use_valgrind = (valgrind != NULL);
+ } 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, 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
* 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. */
- listhead = xcalloc(1, sizeof(struct testlist));
+ listhead = xcalloc(1, struct testlist);
current = NULL;
/*
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. */
if (current == NULL)
current = listhead;
else {
- current->next = xcalloc(1, sizeof(struct testlist));
+ current->next = xcalloc(1, struct testlist);
current = current->next;
}
- current->ts = xcalloc(1, sizeof(struct testset));
+ current->ts = xcalloc(1, struct testset);
current->ts->plan = PLAN_INIT;
- current->ts->file = xstrdup(testname);
+
+ /* Parse the line and store the results in the testset struct. */
+ parse_test_list_line(start, current->ts, source, build);
}
fclose(file);
* 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;
/* Create the initial container list that will hold our results. */
- listhead = xcalloc(1, sizeof(struct testlist));
+ listhead = xcalloc(1, struct testlist);
current = NULL;
/* Walk the list of arguments and create test sets for them. */
if (current == NULL)
current = listhead;
else {
- current->next = xcalloc(1, sizeof(struct testlist));
+ current->next = xcalloc(1, struct testlist);
current = current->next;
}
- current->ts = xcalloc(1, sizeof(struct testset));
+ current->ts = xcalloc(1, struct testset);
current->ts->plan = PLAN_INIT;
current->ts->file = xstrdup(argv[i]);
+ current->ts->command = xcalloc(2, 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. */
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);
* 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;
fflush(stdout);
/* Run the test. */
- ts->path = find_test(ts->file, source, build);
succeeded = test_run(ts, verbose);
fflush(stdout);
if (verbose)
/* If the test fails, we shuffle it over to the fail list. */
if (!succeeded) {
if (failhead == NULL) {
- failhead = xmalloc(sizeof(struct testset));
+ failhead = xcalloc(1, struct testlist);
failtail = failhead;
} else {
- failtail->next = xmalloc(sizeof(struct testset));
+ failtail->next = xcalloc(1, struct testlist);
failtail = failtail->next;
}
failtail->ts = ts;
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);
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. */
#!/usr/bin/perl
#
-# Check URLs in source files.
+# Check for obsolete strings in source files.
#
-# Examine all source files in a distribution for bad URL patterns and report
-# on files that fail this check. Currently, this just checks that all the
-# links to www.eyrie.org are https.
+# Examine all source files in a distribution for obsolete strings and report
+# on files that fail this check. This catches various transitions I want to
+# do globally in all my packages, like changing my personal URLs to https.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2016, 2018-2019 Russ Allbery <eagle@eyrie.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# 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 5.008;
use strict;
use warnings;
use lib "$ENV{C_TAP_SOURCE}/tap/perl";
-use File::Basename qw(basename);
-use Test::More;
use Test::RRA qw(skip_unless_author);
use Test::RRA::Automake qw(all_files automake_setup);
+use File::Basename qw(basename);
+use Test::More;
+
# Bad patterns to search for.
my @BAD_REGEXES = (qr{ http:// \S+ [.]eyrie[.]org }xms);
-my @BAD_STRINGS = qw(rra@stanford.edu);
+my @BAD_STRINGS = qw(rra@stanford.edu RRA_MAINTAINER_TESTS);
+
+# File names to exclude from this check.
+my %EXCLUDE = map { $_ => 1 } qw(NEWS obsolete-strings.t obsolete-strings-t);
# Only run this test for the package author, since it doesn't indicate any
# user-noticable flaw in the package itself.
-skip_unless_author('Documentation URL tests');
+skip_unless_author('Obsolete strings tests');
# Set up Automake testing.
automake_setup();
my ($path) = @_;
my $filename = basename($path);
- # Ignore this check itself (or the Perl version of it) and binary files.
- return if ($filename eq 'urls.t' || $filename eq 'urls-t');
+ # Ignore excluded and binary files.
+ return if $EXCLUDE{$filename};
return if !-T $path;
# Scan the file.
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2013, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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 <errno.h>
*/
struct cleanup_func {
test_cleanup_func func;
+ test_cleanup_func_with_data func_with_data;
+ void *data;
struct cleanup_func *next;
};
static struct cleanup_func *cleanup_funcs = NULL;
* print_desc, which has to be done in a macro. Assumes that format is the
* argument immediately before the variadic arguments.
*/
-#define PRINT_DESC(prefix, format) \
- do { \
- if (format != NULL) { \
- va_list args; \
- if (prefix != NULL) \
- printf("%s", prefix); \
- va_start(args, format); \
- vprintf(format, args); \
- va_end(args); \
- } \
+#define PRINT_DESC(prefix, format) \
+ do { \
+ if (format != NULL) { \
+ va_list args; \
+ printf("%s", prefix); \
+ va_start(args, format); \
+ vprintf(format, args); \
+ va_end(args); \
+ } \
} while (0)
length++;
/* Create the string. */
- result = bmalloc(length);
+ result = bcalloc_type(length, char);
va_start(args, first);
offset = 0;
for (string = first; string != NULL; string = va_arg(args, const char *)) {
}
+/*
+ * Helper function for check_diag_files to handle a single line in a diag
+ * file.
+ *
+ * The general scheme here used is as follows: read one line of output. If we
+ * get NULL, check for an error. If there was one, bail out of the test
+ * program; otherwise, return, and the enclosing loop will check for EOF.
+ *
+ * If we get some data, see if it ends in a newline. If it doesn't end in a
+ * newline, we have one of two cases: our buffer isn't large enough, in which
+ * case we resize it and try again, or we have incomplete data in the file, in
+ * which case we rewind the file and will try again next time.
+ *
+ * Returns a boolean indicating whether the last line was incomplete.
+ */
+static int
+handle_diag_file_line(struct diag_file *file, fpos_t where)
+{
+ int size;
+ size_t length;
+
+ /* Read the next line from the file. */
+ size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
+ if (fgets(file->buffer, size, file->file) == NULL) {
+ if (ferror(file->file))
+ sysbail("cannot read from %s", file->name);
+ return 0;
+ }
+
+ /*
+ * See if the line ends in a newline. If not, see which error case we
+ * have.
+ */
+ length = strlen(file->buffer);
+ if (file->buffer[length - 1] != '\n') {
+ int incomplete = 0;
+
+ /* Check whether we ran out of buffer space and resize if so. */
+ if (length < file->bufsize - 1)
+ incomplete = 1;
+ else {
+ file->bufsize += BUFSIZ;
+ file->buffer =
+ breallocarray_type(file->buffer, file->bufsize, char);
+ }
+
+ /*
+ * On either incomplete lines or too small of a buffer, rewind
+ * and read the file again (on the next pass, if incomplete).
+ * It's simpler than trying to double-buffer the file.
+ */
+ if (fsetpos(file->file, &where) < 0)
+ sysbail("cannot set position in %s", file->name);
+ return incomplete;
+ }
+
+ /* We saw a complete line. Print it out. */
+ printf("# %s", file->buffer);
+ return 0;
+}
+
+
/*
* Check all registered diag_files for any output. We only print out the
* output if we see a complete line; otherwise, we wait for the next newline.
{
struct diag_file *file;
fpos_t where;
- size_t length;
- int size, incomplete;
+ int incomplete;
/*
- * Walk through each file and read each line of output available. The
- * general scheme here used is as follows: try to read a line of output at
- * a time. If we get NULL, check for EOF; on EOF, advance to the next
- * file.
- *
- * If we get some data, see if it ends in a newline. If it doesn't end in
- * a newline, we have one of two cases: our buffer isn't large enough, in
- * which case we resize it and try again, or we have incomplete data in
- * the file, in which case we rewind the file and will try again next
- * time.
+ * Walk through each file and read each line of output available.
*/
for (file = diag_files; file != NULL; file = file->next) {
clearerr(file->file);
/* Continue until we get EOF or an incomplete line of data. */
incomplete = 0;
while (!feof(file->file) && !incomplete) {
- size = file->bufsize > INT_MAX ? INT_MAX : (int) file->bufsize;
- if (fgets(file->buffer, size, file->file) == NULL) {
- if (ferror(file->file))
- sysbail("cannot read from %s", file->name);
- continue;
- }
-
- /*
- * See if the line ends in a newline. If not, see which error
- * case we have. Use UINT_MAX as a substitute for SIZE_MAX (see
- * the comment for breallocarray).
- */
- length = strlen(file->buffer);
- if (file->buffer[length - 1] != '\n') {
- if (length < file->bufsize - 1)
- incomplete = 1;
- else {
- if (file->bufsize >= UINT_MAX - BUFSIZ)
- sysbail("line too long in %s", file->name);
- file->bufsize += BUFSIZ;
- file->buffer = brealloc(file->buffer, file->bufsize);
- }
-
- /*
- * On either incomplete lines or too small of a buffer, rewind
- * and read the file again (on the next pass, if incomplete).
- * It's simpler than trying to double-buffer the file.
- */
- if (fsetpos(file->file, &where) < 0)
- sysbail("cannot set position in %s", file->name);
- continue;
- }
-
- /* We saw a complete line. Print it out. */
- printf("# %s", file->buffer);
+ incomplete = handle_diag_file_line(file, where);
}
}
}
*/
primary = (_process == 0 || getpid() == _process);
while (cleanup_funcs != NULL) {
- cleanup_funcs->func(success, primary);
+ if (cleanup_funcs->func_with_data) {
+ void *data = cleanup_funcs->data;
+
+ cleanup_funcs->func_with_data(success, primary, data);
+ } else {
+ cleanup_funcs->func(success, primary);
+ }
current = cleanup_funcs;
cleanup_funcs = cleanup_funcs->next;
free(current);
/*
- * 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++;
}
/*
- * 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++;
}
/*
- * 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 = (const unsigned char *) left;
+ const unsigned char *right_c = (const unsigned char *) right;
+
+ for (i = 0; i < len; i++) {
+ if (left_c[i] != right_c[i])
+ diag("offset %lu: left %02x, right %02x", (unsigned long) i,
+ left_c[i], right_c[i]);
+ }
printf("not ok %lu", testnum++);
_failed++;
}
{
struct diag_file *file, *prev;
- file = bcalloc(1, sizeof(struct diag_file));
+ file = bcalloc_type(1, struct diag_file);
file->name = bstrdup(name);
file->file = fopen(file->name, "r");
if (file->file == NULL)
sysbail("cannot open %s", name);
- file->buffer = bmalloc(BUFSIZ);
+ file->buffer = bcalloc_type(BUFSIZ, char);
file->bufsize = BUFSIZ;
if (diag_files == NULL)
diag_files = file;
{
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));
size_t len;
len = strlen(s) + 1;
- p = malloc(len);
+ p = (char *) malloc(len);
if (p == NULL)
sysbail("failed to strdup %lu bytes", (unsigned long) len);
memcpy(p, s, len);
for (p = s; (size_t)(p - s) < n && *p != '\0'; p++)
;
length = (size_t)(p - s);
- copy = malloc(length + 1);
- if (p == NULL)
+ copy = (char *) malloc(length + 1);
+ if (copy == NULL)
sysbail("failed to strndup %lu bytes", (unsigned long) length);
memcpy(copy, s, length);
copy[length] = '\0';
free(path);
}
-
-/*
- * Register a cleanup function that is called when testing ends. All such
- * registered functions will be run by finish.
- */
-void
-test_cleanup_register(test_cleanup_func func)
+static void
+register_cleanup(test_cleanup_func func,
+ test_cleanup_func_with_data func_with_data, void *data)
{
struct cleanup_func *cleanup, **last;
- cleanup = bmalloc(sizeof(struct cleanup_func));
+ cleanup = bcalloc_type(1, struct cleanup_func);
cleanup->func = func;
+ cleanup->func_with_data = func_with_data;
+ cleanup->data = data;
cleanup->next = NULL;
last = &cleanup_funcs;
while (*last != NULL)
last = &(*last)->next;
*last = cleanup;
}
+
+/*
+ * Register a cleanup function that is called when testing ends. All such
+ * registered functions will be run by finish.
+ */
+void
+test_cleanup_register(test_cleanup_func func)
+{
+ register_cleanup(func, NULL, NULL);
+}
+
+/*
+ * Same as above, but also allows an opaque pointer to be passed to the cleanup
+ * function.
+ */
+void
+test_cleanup_register_with_data(test_cleanup_func_with_data func, void *data)
+{
+ register_cleanup(NULL, func, data);
+}
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016
- * Russ Allbery <eagle@eyrie.org>
- * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2011, 2012, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2009-2019 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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
__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, ...)
char *bstrndup(const char *, size_t)
__attribute__((__malloc__, __nonnull__, __warn_unused_result__));
+/*
+ * Macros that cast the return value from b* memory functions, making them
+ * usable in C++ code and providing some additional type safety.
+ */
+#define bcalloc_type(n, type) ((type *) bcalloc((n), sizeof(type)))
+#define breallocarray_type(p, n, type) \
+ ((type *) breallocarray((p), (n), sizeof(type)))
+
/*
* Find a test file under C_TAP_BUILD or C_TAP_SOURCE, returning the full
* path. The returned path should be freed with test_file_path_free().
* The function must return void and will be passed two arguments: an int that
* will be true if the test completed successfully and false otherwise, and an
* int that will be true if the cleanup function is run in the primary process
- * (the one that called plan or plan_lazy) and false otherwise.
+ * (the one that called plan or plan_lazy) and false otherwise. If
+ * test_cleanup_register_with_data is used instead, a generic pointer can be
+ * provided and will be passed to the cleanup function as a third argument.
+ *
+ * test_cleanup_register_with_data is the better API and should have been the
+ * only API. test_cleanup_register was an API error preserved for backward
+ * cmpatibility.
*/
typedef void (*test_cleanup_func)(int, int);
+typedef void (*test_cleanup_func_with_data)(int, int, void *);
+
void test_cleanup_register(test_cleanup_func) __attribute__((__nonnull__));
+void test_cleanup_register_with_data(test_cleanup_func_with_data, void *)
+ __attribute__((__nonnull__));
END_DECLS
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014
+ * Copyright 2017 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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 <config.h>
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')
/*
- * 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);
/*
- * 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);
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;
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2006, 2007, 2009, 2011, 2012, 2013, 2014
+ * Copyright 2017, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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
* tests require both keytab and password, but PKINIT is not required.
*/
enum kerberos_needs {
- TAP_KRB_NEEDS_NONE = 0x00,
- TAP_KRB_NEEDS_KEYTAB = 0x01,
+ /* clang-format off */
+ TAP_KRB_NEEDS_NONE = 0x00,
+ TAP_KRB_NEEDS_KEYTAB = 0x01,
TAP_KRB_NEEDS_PASSWORD = 0x02,
- TAP_KRB_NEEDS_BOTH = 0x01 | 0x02,
- TAP_KRB_NEEDS_PKINIT = 0x04
+ TAP_KRB_NEEDS_BOTH = 0x01 | 0x02,
+ TAP_KRB_NEEDS_PKINIT = 0x04
+ /* clang-format on */
};
BEGIN_DECLS
void kerberos_generate_conf(const char *realm);
void kerberos_cleanup_conf(void);
-/* Thes interfaces are only available with native Kerberos support. */
+/* These interfaces are only available with native Kerberos support. */
#ifdef HAVE_KRB5
/* Bail out with an error, appending the Kerberos error message. */
-void bail_krb5(krb5_context, krb5_error_code, const char *format, ...)
+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, ...)
+void diag_krb5(krb5_context, long, const char *format, ...)
__attribute__((__nonnull__(3), __format__(printf, 3, 4)));
/*
# <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2009, 2010, 2011, 2012, 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2006, 2007, 2008, 2013
+# Copyright 2009-2012, 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2006-2008, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# 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 () {
* This file is part of C TAP Harness. The current version plus supporting
* documentation is at <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
*
- * Copyright 2008, 2012, 2013, 2015 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2008, 2012-2013, 2015 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* 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
# 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;
-use 5.006;
+use 5.008;
+use base qw(Exporter);
use strict;
use warnings;
-use Exporter;
+use Carp qw(croak);
use File::Temp;
-use Test::More;
-# For Perl 5.006 compatibility.
-## no critic (ClassHierarchies::ProhibitExplicitISA)
+# Abort if Test::More was loaded before Test::RRA to be sure that we get the
+# benefits of the Test::More probing below.
+if ($INC{'Test/More.pm'}) {
+ croak('Test::More loaded before Test::RRA');
+}
+
+# Red Hat's base perl package doesn't include Test::More (one has to install
+# the perl-core package in addition). Try to detect this and skip any Perl
+# tests if Test::More is not present. This relies on Test::RRA being included
+# before Test::More.
+eval {
+ require Test::More;
+ Test::More->import();
+};
+if ($@) {
+ print "1..0 # SKIP Test::More required for test\n"
+ or croak('Cannot write to stdout');
+ exit 0;
+}
# Declare variables that should be set in BEGIN for robustness.
-our (@EXPORT_OK, @ISA, $VERSION);
+our (@EXPORT_OK, $VERSION);
# Set $VERSION and everything export-related in a BEGIN block for robustness
# against circular module loading (not that we load any modules, but
# consistency is good).
BEGIN {
- @ISA = qw(Exporter);
@EXPORT_OK = qw(
is_file_contents skip_unless_author skip_unless_automated use_prereq
);
# 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 = '6.02';
+ $VERSION = '8.02';
}
# Compare a string to the contents of a file, similar to the standard is()
return;
}
- # Otherwise, we show a diff, but only if we have IPC::System::Simple.
- eval { require IPC::System::Simple };
+ # Otherwise, we show a diff, but only if we have IPC::System::Simple and
+ # diff succeeds. Otherwise, we fall back on showing the full expected and
+ # seen output.
+ eval {
+ require IPC::System::Simple;
+
+ my $tmp = File::Temp->new();
+ my $tmpname = $tmp->filename;
+ print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n");
+ my @command = ('diff', '-u', $expected, $tmpname);
+ my $diff = IPC::System::Simple::capturex([0 .. 1], @command);
+ diag($diff);
+ };
if ($@) {
- ok(0, $message);
- return;
+ diag('Expected:');
+ diag($expected);
+ diag('Seen:');
+ diag($data);
}
- # They're not equal. Write out what we got so that we can run diff.
- my $tmp = File::Temp->new();
- my $tmpname = $tmp->filename;
- print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n");
- my @command = ('diff', '-u', $expected, $tmpname);
- my $diff = IPC::System::Simple::capturex([0 .. 1], @command);
- diag($diff);
-
- # Remove the temporary file and report failure.
+ # Report failure.
ok(0, $message);
return;
}
sub skip_unless_author {
my ($description) = @_;
if (!$ENV{AUTHOR_TESTING}) {
- plan skip_all => "$description only run for author";
+ plan(skip_all => "$description only run for author");
}
return;
}
for my $env (qw(AUTOMATED_TESTING RELEASE_TESTING AUTHOR_TESTING)) {
return if $ENV{$env};
}
- plan skip_all => "$description normally skipped";
+ plan(skip_all => "$description normally skipped");
return;
}
use $module $version \@imports;
1;
};
- $error = $@;
+ $error = $@;
$sigdie = $SIG{__DIE__} || undef;
}
# If the use failed for any reason, skip the test.
if (!$result || $error) {
my $name = length($version) > 0 ? "$module $version" : $module;
- plan skip_all => "$name required for test";
+ plan(skip_all => "$name required for test");
}
# If the module set $SIG{__DIE__}, we cleared that via local. Restore it.
It assumes Russ Allbery's Perl module layout and test conventions and will
only be useful for other people if they use the same conventions.
+This module B<must> be loaded before Test::More or it will abort during
+import. It will skip the test (by printing a skip message to standard output
+and exiting with status 0, equivalent to C<plan skip_all>) during import if
+Test::More is not available. This allows tests written in Perl using this
+module to be skipped if run on a system with Perl but not Test::More, such as
+Red Hat systems with the C<perl> package but not the C<perl-core> package
+installed.
+
=head1 FUNCTIONS
None of these functions are imported by default. The ones used by a script
=head1 COPYRIGHT AND LICENSE
-Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
+Copyright 2016, 2018-2019 Russ Allbery <eagle@eyrie.org>
+
+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 copy
Consensus|https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
# 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;
-use 5.006;
+use 5.008;
+use base qw(Exporter);
use strict;
use warnings;
-# For Perl 5.006 compatibility.
-## no critic (ClassHierarchies::ProhibitExplicitISA)
-
use Exporter;
use File::Find qw(find);
use File::Spec;
use lib $PERL_BLIB_LIB;
# Declare variables that should be set in BEGIN for robustness.
-our (@EXPORT_OK, @ISA, $VERSION);
+our (@EXPORT_OK, $VERSION);
# Set $VERSION and everything export-related in a BEGIN block for robustness
# against circular module loading (not that we load any modules, but
# consistency is good).
BEGIN {
- @ISA = qw(Exporter);
@EXPORT_OK = qw(
all_files automake_setup perl_dirs test_file_path test_tmpdir
);
# 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 = '6.02';
+ $VERSION = '8.02';
}
# Directories to skip globally when looking for all files, or for directories
# that could contain Perl files.
-my @GLOBAL_SKIP = qw(.git _build autom4te.cache build-aux);
+my @GLOBAL_SKIP = qw(
+ .git .pc _build autom4te.cache build-aux perl/_build perl/blib
+);
# 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 config.h.in~ configure);
+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
my $file = $_;
my $path = $File::Find::name;
$path =~ s{ \A [.]/ }{}xms;
- if ($skip{$path} or $files_skip{$file} or $file =~ m{ [.] lo \z }xms) {
+ if ($skip{$path} || $files_skip{$file} || $file =~ m{ [.] lo \z }xms) {
$File::Find::prune = 1;
return;
}
@builddirs = File::Spec->splitdir($builddirs);
pop(@builddirs);
my $libdir = File::Spec->catdir(@builddirs, $LIBRARY_PATH);
- my $path = File::Spec->catpath($buildvol, $libdir, q{});
+ my $path = File::Spec->catpath($buildvol, $libdir, q{});
if (-d "$path/.libs") {
$path .= '/.libs';
}
}
# Convert the skip lists into hashes for convenience.
- my %skip = map { $_ => 1 } @skip, 'tests';
+ my %skip = map { $_ => 1 } @skip, 'tests';
my %skip_tests = map { $_ => 1 } @skip_tests;
# Build the list of top-level directories to test.
=head1 COPYRIGHT AND LICENSE
-Copyright 2014, 2015 Russ Allbery <eagle@eyrie.org>
+Copyright 2014-2015, 2018-2020 Russ Allbery <eagle@eyrie.org>
Copyright 2013 The Board of Trustees of the Leland Stanford Junior University
available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
# 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;
-use 5.006;
+use 5.008;
+use base qw(Exporter);
use strict;
use warnings;
-# For Perl 5.006 compatibility.
-## no critic (ClassHierarchies::ProhibitExplicitISA)
-
-use Exporter;
use Test::More;
# Declare variables that should be set in BEGIN for robustness.
-our (@EXPORT_OK, @ISA, $VERSION);
+our (@EXPORT_OK, $VERSION);
# Set $VERSION and everything export-related in a BEGIN block for robustness
# against circular module loading (not that we load any modules, but
# consistency is good).
BEGIN {
- @ISA = qw(Exporter);
@EXPORT_OK = qw(
$COVERAGE_LEVEL @COVERAGE_SKIP_TESTS @CRITIC_IGNORE $LIBRARY_PATH
$MINIMUM_VERSION %MINIMUM_VERSION @MODULE_VERSION_IGNORE
# 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 = '6.02';
+ $VERSION = '8.02';
}
# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for
=head1 COPYRIGHT AND LICENSE
-Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org>
+Copyright 2015-2016, 2019 Russ Allbery <eagle@eyrie.org>
-Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
+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 copy
available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>.
=cut
+
+# Local Variables:
+# copyright-at-end-flag: t
+# End:
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2002, 2004, 2005, 2013, 2016 Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010, 2011, 2013, 2014
+ * Copyright 2002, 2004-2005, 2013, 2016-2017 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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 <config.h>
* 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;
pid = strtol(buffer, NULL, 10);
if (pid <= 0)
bail("cannot read PID from %s", path);
- return pid;
+ return (pid_t) pid;
}
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * 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
* 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
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2011, 2012 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2011-2012 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* 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 <config.h>
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2011, 2012 Russ Allbery <eagle@eyrie.org>
+ * Copyright 2011-2012 Russ Allbery <eagle@eyrie.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* 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
# Test suite for Heimdal per-principal history.
#
# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2020 Russ Allbery <eagle@eyrie.org>
# Copyright 2014
# The Board of Trustees of the Leland Stanford Junior University
#
use lib "$ENV{SOURCE}/tap/perl";
-use Fcntl qw(O_CREAT O_RDWR);
-use Test::More;
use Test::RRA qw(use_prereq);
use Test::RRA::Automake qw(test_file_path test_tmpdir);
+use Fcntl qw(O_CREAT O_RDWR);
+use Test::More;
+
# Not all of these are used by the test suite, but the rest are required to
# run the program we're testing, so make sure they can all be loaded.
use_prereq('DB_File::Lock');
is($status, $test_ref->{status} || 0, "$test_ref->{name} (status)");
if (defined($test_ref->{error})) {
is($err, $test_ref->{error}, '...error message');
- is($out, q{}, '...no output');
+ is($out, q{}, '...no output');
} else {
is($err, q{}, '...no errors');
is($out, 'APPROVED', '...approved');
# Test suite for basic Heimdal external strength checking functionality.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016, 2017 Russ Allbery <eagle@eyrie.org>
+# Copyright 2016, 2017, 2020 Russ Allbery <eagle@eyrie.org>
# Copyright 2009, 2012, 2013, 2014
# The Board of Trustees of the Leland Stanford Junior University
#
# Run the password strength checker.
my ($out, $err);
my $harness = run([$program, $principal], \$in, \$out, \$err);
- my $status = $? >> 8;
+ my $status = $? >> 8;
# Return the results.
return ($status, $out, $err);
is($status, $test_ref->{status} || 0, "$test_ref->{name} (status)");
if (defined($test_ref->{error})) {
is($err, $test_ref->{error}, '...error message');
- is($out, q{}, '...no output');
+ is($out, q{}, '...no output');
} else {
is($err, q{}, '...no errors');
is($out, 'APPROVED', '...approved');
# Test suite for krb5-strength-wordlist SQLite database generation
#
# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2020 Russ Allbery <eagle@eyrie.org>
# Copyright 2014
# The Board of Trustees of the Leland Stanford Junior University
#
use lib "$ENV{SOURCE}/tap/perl";
-use Test::More;
use Test::RRA qw(use_prereq);
use Test::RRA::Automake qw(automake_setup test_file_path test_tmpdir);
+use Test::More;
+
# Load prerequisite modules.
use_prereq('DBI');
use_prereq('DBD::SQLite');
# Test suite for krb5-strength-wordlist filtering functions.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
# Copyright 2014
# The Board of Trustees of the Leland Stanford Junior University
#
use lib "$ENV{SOURCE}/tap/perl";
-use Encode qw(encode);
-use Test::More;
use Test::RRA qw(use_prereq);
use Test::RRA::Automake qw(automake_setup test_file_path test_tmpdir);
+use Encode qw(encode);
+use Test::More;
+
# Load prerequisite modules.
use_prereq('IPC::Run', 'run');
use_prereq('Perl6::Slurp', 'slurp');
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2010, 2011, 2013, 2014
+ * Copyright 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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 <config.h>
/*
* Test functions.
*/
-static void
+__attribute__((__noreturn__)) static void
test_warn(void *data UNUSED)
{
krb5_context ctx;
exit(0);
}
-static void
+__attribute__((__noreturn__)) static void
test_die(void *data UNUSED)
{
krb5_context ctx;
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2002, 2004, 2005, 2015 Russ Allbery <eagle@eyrie.org>
- * Copyright 2009, 2010, 2011, 2012
+ * Copyright 2002, 2004-2005, 2015, 2017, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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 <config.h>
{
warn("warning");
}
-static void
+
+__attribute__((__noreturn__)) static void
test2(void *data UNUSED)
{
die("fatal");
}
+
static void
test3(void *data UNUSED)
{
errno = EPERM;
syswarn("permissions");
}
-static void
+
+__attribute__((__noreturn__)) static void
test4(void *data UNUSED)
{
errno = EACCES;
sysdie("fatal access");
}
+
static void
test5(void *data UNUSED)
{
message_program_name = "test5";
warn("warning");
}
-static void
+
+__attribute__((__noreturn__)) static void
test6(void *data UNUSED)
{
message_program_name = "test6";
die("fatal");
}
+
static void
test7(void *data UNUSED)
{
errno = EPERM;
syswarn("perms %d", 7);
}
-static void
+
+__attribute__((__noreturn__)) static void
test8(void *data UNUSED)
{
message_program_name = "test8";
return 10;
}
-static void
+__attribute__((__noreturn__)) static void
test9(void *data UNUSED)
{
message_fatal_cleanup = return10;
die("fatal");
}
-static void
+
+__attribute__((__noreturn__)) static void
test10(void *data UNUSED)
{
message_program_name = 0;
errno = EPERM;
sysdie("fatal perm");
}
-static void
+
+__attribute__((__noreturn__)) static void
test11(void *data UNUSED)
{
message_program_name = "test11";
sysdie("fatal");
}
-static void __attribute__((__format__(printf, 2, 0)))
+__attribute__((__format__(printf, 2, 0))) static void
log_msg(size_t len, const char *format, va_list args, int error)
{
fprintf(stderr, "%lu %d ", (unsigned long) len, error);
message_handlers_warn(1, log_msg);
warn("warning");
}
-static void
+
+__attribute__((__noreturn__)) static void
test13(void *data UNUSED)
{
message_handlers_die(1, log_msg);
die("fatal");
}
+
static void
test14(void *data UNUSED)
{
errno = EPERM;
syswarn("warning");
}
-static void
+
+__attribute__((__noreturn__)) static void
test15(void *data UNUSED)
{
message_handlers_die(2, log_msg, log_msg);
errno = EPERM;
sysdie("fatal");
}
+
static void
test16(void *data UNUSED)
{
errno = EPERM;
syswarn("warning");
}
+
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)
{
message_handlers_notice(1, log_msg);
notice("foo");
}
+
static void
test21(void *data UNUSED)
{
message_program_name = "test23";
debug("baz");
}
-static void
+
+__attribute__((__noreturn__)) static void
test22(void *data UNUSED)
{
message_handlers_die(0);
die("hi mom!");
}
+
static void
test23(void *data UNUSED)
{
message_handlers_warn(0);
warn("this is a test");
}
+
static void
test24(void *data UNUSED)
{
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2000, 2001, 2006, 2014, 2016 Russ Allbery <eagle@eyrie.org>
-# Copyright 2008, 2009, 2010, 2012
+# Copyright 2000-2001, 2006, 2014, 2016, 2019-2020
+# Russ Allbery <eagle@eyrie.org>
+# 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
# 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"
cd "$C_TAP_BUILD/util"
-# Run an xmalloc test. Takes the description, the expectd exit status, the
+# Run an xmalloc test. Takes the description, the expected exit status, the
# output, and the arguments.
ok_xmalloc () {
local desc w_status w_output output status
# We assume that there are enough miscellaneous allocations that an allocation
# exactly as large as the limit will always fail.
ok_xmalloc "malloc fail" 1 \
- "failed to malloc 30000000 bytes at xmalloc.c line 41" \
+ "failed to malloc 30000000 bytes at xmalloc.c line 42" \
"m" "30000000" "30000000"
ok_xmalloc "realloc fail" 1 \
- "failed to realloc 30000000 bytes at xmalloc.c line 69" \
+ "failed to realloc 30000000 bytes at xmalloc.c line 71" \
"r" "30000000" "30000000"
ok_xmalloc "reallocarray fail" 1 \
- "failed to reallocarray 30000000 bytes at xmalloc.c line 99" \
+ "failed to reallocarray 30000000 bytes at xmalloc.c line 100" \
"y" "30000000" "30000000"
ok_xmalloc "strdup fail" 1 \
- "failed to strdup 30000000 bytes at xmalloc.c line 130" \
+ "failed to strdup 30000000 bytes at xmalloc.c line 131" \
"s" "30000000" "30000000"
ok_xmalloc "strndup fail" 1 \
- "failed to strndup 30000000 bytes at xmalloc.c line 176" \
+ "failed to strndup 30000000 bytes at xmalloc.c line 177" \
"n" "30000000" "30000000"
ok_xmalloc "calloc fail" 1 \
- "failed to calloc 30000000 bytes at xmalloc.c line 200" \
+ "failed to calloc 30000000 bytes at xmalloc.c line 201" \
"c" "30000000" "30000000"
ok_xmalloc "asprintf fail" 1 \
- "failed to asprintf 30000000 bytes at xmalloc.c line 224" \
+ "failed to asprintf 30000000 bytes at xmalloc.c line 225" \
"a" "30000000" "30000000"
ok_xmalloc "vasprintf fail" 1 \
- "failed to vasprintf 30000000 bytes at xmalloc.c line 243" \
+ "failed to vasprintf 30000000 bytes at xmalloc.c line 244" \
"v" "30000000" "30000000"
# Check our custom error handler.
-ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 41" \
+ok_xmalloc "malloc custom" 1 "malloc 30000000 xmalloc.c 42" \
"M" "30000000" "30000000"
-ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 69" \
+ok_xmalloc "realloc custom" 1 "realloc 30000000 xmalloc.c 71" \
"R" "30000000" "30000000"
-ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 99" \
+ok_xmalloc "reallocarray custom" 1 "reallocarray 30000000 xmalloc.c 100" \
"Y" "30000000" "30000000"
-ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 130" \
+ok_xmalloc "strdup custom" 1 "strdup 30000000 xmalloc.c 131" \
"S" "30000000" "30000000"
-ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 176" \
+ok_xmalloc "strndup custom" 1 "strndup 30000000 xmalloc.c 177" \
"N" "30000000" "30000000"
-ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 200" \
+ok_xmalloc "calloc custom" 1 "calloc 30000000 xmalloc.c 201" \
"C" "30000000" "30000000"
-ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 224" \
+ok_xmalloc "asprintf custom" 1 "asprintf 30000000 xmalloc.c 225" \
"A" "30000000" "30000000"
-ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 243" \
+ok_xmalloc "vasprintf custom" 1 "vasprintf 30000000 xmalloc.c 244" \
"V" "30000000" "30000000"
# Check the smaller ones again just for grins.
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2000, 2001, 2006 Russ Allbery <eagle@eyrie.org>
- * Copyright 2008, 2012, 2013, 2014
+ * Copyright 2000-2001, 2006, 2017, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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
* 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"
#include <config.h>
#include <portable/system.h>
+#include <assert.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_SYS_TIME_H
* 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);
char *buffer;
size_t i;
+ assert(size > 10);
buffer = xmalloc(10);
if (buffer == NULL)
return 0;
buffer = xrealloc(buffer, size);
if (buffer == NULL)
return 0;
- if (size > 0)
- memset(buffer + 10, 2, size - 10);
+ memset(buffer + 10, 2, size - 10);
for (i = 0; i < 10; i++)
if (buffer[i] != 1)
return 0;
code = argv[1][0];
if (isupper(code)) {
xmalloc_error_handler = test_handler;
- code = tolower(code);
+ code = (unsigned char) tolower(code);
}
/*
#endif
}
+ /* clang-format off */
switch (code) {
- case 'c':
- exit(test_calloc(size) ? willfail : 1);
- case 'm':
- exit(test_malloc(size) ? willfail : 1);
- case 'r':
- exit(test_realloc(size) ? willfail : 1);
- case 'y':
- exit(test_reallocarray(4, size / 4) ? willfail : 1);
- case 's':
- exit(test_strdup(size) ? willfail : 1);
- 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;
+ case 'c': exit(test_calloc(size) ? willfail : 1);
+ case 'm': exit(test_malloc(size) ? willfail : 1);
+ case 'r': exit(test_realloc(size) ? willfail : 1);
+ case 'y': exit(test_reallocarray(4, size / 4) ? willfail : 1);
+ case 's': exit(test_strdup(size) ? willfail : 1);
+ 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]);
}
+ /* clang-format on */
+
exit(1);
}
require Benchmark;
my $iterations = $HASH_ITERATIONS;
while (1) {
- my $hash = sub { password_hash($password, $iterations) };
+ my $hash = sub { password_hash($password, $iterations) };
my $times = Benchmark::timethis(20, $hash, q{}, 'none');
# Extract the CPU time from the formatted time string. This will be
# Run the external quality checking program. If we're root, we'll run it
# as the strength checking user and group.
- my $in = "principal: $principal\nnew-password: $password\nend\n";
+ my $in = "principal: $principal\nnew-password: $password\nend\n";
my $init = sub { drop_privileges($STRENGTH_USER, $STRENGTH_GROUP) };
my ($out, $err);
run([$path, $principal], \$in, \$out, \$err, init => $init);
* dictionary.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2009, 2013
* The Board of Trustees of the Leland Stanford Junior University
*
read_key(const char *key, char *buffer, size_t length)
{
char *p;
+ int size = (length < INT_MAX) ? (int) length : INT_MAX;
- if (fgets(buffer, length, stdin) == NULL)
+ if (fgets(buffer, size, stdin) == NULL)
sysdie("Cannot read %s", key);
if (strlen(buffer) < 1 || buffer[strlen(buffer) - 1] != '\n')
die("Malformed or too long %s line", key);
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014 Russ Allbery <eagle@eyrie.org>
+ * 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
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * 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
* 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 <config.h>
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * 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
* 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
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
- * Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org>
- * Copyright 2008, 2009, 2010, 2013, 2014
+ * Copyright 2015-2016, 2020 Russ Allbery <eagle@eyrie.org>
+ * 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.
* 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 <config.h>
* duplication since we can't assume variadic macros, but I can at least make
* it easier to write and keep them consistent.
*/
-#define HANDLER_FUNCTION(type) \
- void message_handlers_##type(unsigned int count, ...) \
- { \
- va_list args; \
- \
- va_start(args, count); \
- message_handlers(&type##_handlers, count, args); \
- va_end(args); \
+/* clang-format off */
+#define HANDLER_FUNCTION(type) \
+ void \
+ message_handlers_ ## type(unsigned int count, ...) \
+ { \
+ va_list args; \
+ \
+ va_start(args, count); \
+ message_handlers(& type ## _handlers, count, args); \
+ va_end(args); \
}
+/* clang-format on */
HANDLER_FUNCTION(debug)
HANDLER_FUNCTION(notice)
HANDLER_FUNCTION(warn)
* Do the same sort of wrapper to generate all of the separate syslog logging
* functions.
*/
-#define SYSLOG_FUNCTION(name, type) \
- void message_log_syslog_##name(size_t l, const char *f, va_list a, int e) \
- { \
- message_log_syslog(LOG_##type, l, f, a, e); \
+/* clang-format off */
+#define SYSLOG_FUNCTION(name, type) \
+ void \
+ message_log_syslog_ ## name(size_t l, const char *f, va_list a, int e) \
+ { \
+ message_log_syslog(LOG_ ## type, l, f, a, e); \
}
-SYSLOG_FUNCTION(debug, DEBUG)
-SYSLOG_FUNCTION(info, INFO)
-SYSLOG_FUNCTION(notice, NOTICE)
+SYSLOG_FUNCTION(debug, DEBUG)
+SYSLOG_FUNCTION(info, INFO)
+SYSLOG_FUNCTION(notice, NOTICE)
SYSLOG_FUNCTION(warning, WARNING)
-SYSLOG_FUNCTION(err, ERR)
-SYSLOG_FUNCTION(crit, CRIT)
+SYSLOG_FUNCTION(err, ERR)
+SYSLOG_FUNCTION(crit, CRIT)
+/* clang-format on */
/*
*
* Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2015 Russ Allbery <eagle@eyrie.org>
- * Copyright 2008, 2010, 2013, 2014
+ * 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.
* 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
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
+ * Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2015 Russ Allbery <eagle@eyrie.org>
- * 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.
* 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 <config.h>
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
- * Copyright 2010, 2012, 2013, 2014
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * 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.
* 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
/* 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