From 57a5a0095c3fe0f22dcbb9d99a82cc94f2b608c7 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 14:30:53 -0800 Subject: Update to rra-c-util 5.10 and C TAP Harness 3.4 Update to rra-c-util 5.10: * Add missing va_end to xasprintf implementation. * Fix Perl test suite framework for new Automake relative paths. * Improve portability to Kerberos included in Solaris 10. * Use appropriate warning flags with Clang (currently not warning clean). Update to C TAP Harness 3.4: * Fix segfault in runtests with an empty test list. * Display verbose test results with -v or C_TAP_VERBOSE. * Test infrastructure builds cleanly with Clang warnings. * Support comments and blank lines in test lists. --- portable/asprintf.c | 6 +++++- portable/krb5-extra.c | 3 +++ portable/krb5.h | 4 +++- portable/macros.h | 3 ++- portable/mkstemp.c | 5 ++++- portable/reallocarray.c | 8 ++++---- portable/setenv.c | 24 +++++++++--------------- portable/snprintf.c | 2 ++ portable/strlcat.c | 1 + portable/strlcpy.c | 1 + portable/system.h | 4 ++-- 11 files changed, 36 insertions(+), 25 deletions(-) (limited to 'portable') diff --git a/portable/asprintf.c b/portable/asprintf.c index eb2b713..9693842 100644 --- a/portable/asprintf.c +++ b/portable/asprintf.c @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -28,11 +29,14 @@ * with the system versions. */ #if TESTING +# undef asprintf +# undef vasprintf # define asprintf test_asprintf # define vasprintf test_vasprintf int test_asprintf(char **, const char *, ...) __attribute__((__format__(printf, 2, 3))); -int test_vasprintf(char **, const char *, va_list); +int test_vasprintf(char **, const char *, va_list) + __attribute__((__format__(printf, 2, 0))); #endif diff --git a/portable/krb5-extra.c b/portable/krb5-extra.c index b1c8b8d..c8309a4 100644 --- a/portable/krb5-extra.c +++ b/portable/krb5-extra.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -33,6 +34,8 @@ # include # elif defined(HAVE_ET_COM_ERR_H) # include +# elif defined(HAVE_KERBEROSV5_COM_ERR_H) +# include # else # include # endif diff --git a/portable/krb5.h b/portable/krb5.h index 6dfffd5..34f960e 100644 --- a/portable/krb5.h +++ b/portable/krb5.h @@ -42,8 +42,10 @@ #endif #include -#ifdef HAVE_KRB5_H +#if defined(HAVE_KRB5_H) # include +#elif defined(HAVE_KERBEROSV5_KRB5_H) +# include #else # include #endif diff --git a/portable/macros.h b/portable/macros.h index b5093f5..d4cc2cc 100644 --- a/portable/macros.h +++ b/portable/macros.h @@ -37,7 +37,8 @@ * variadic macro support. */ #if !defined(__attribute__) && !defined(__alloc_size__) -# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) +# if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) \ + && !defined(__clang__) # define __alloc_size__(spec, args...) /* empty */ # endif #endif diff --git a/portable/mkstemp.c b/portable/mkstemp.c index 2cbfe08..7c733a4 100644 --- a/portable/mkstemp.c +++ b/portable/mkstemp.c @@ -23,7 +23,10 @@ #include #include -#include +#ifdef HAVE_SYS_TIME_H +# include +#endif +#include /* * If we're running the test suite, rename mkstemp to avoid conflicts with the diff --git a/portable/reallocarray.c b/portable/reallocarray.c index 7d40a7a..e9404e9 100644 --- a/portable/reallocarray.c +++ b/portable/reallocarray.c @@ -1,10 +1,10 @@ /* * Replacement for a missing reallocarray. * - * Provides the same functionality as the OpenBSD library function reallocrray - * for those systems that don't have it. This function is the same as - * realloc, but takes the size arguments in the same form as calloc and checks - * for overflow so that the caller doesn't need to. + * Provides the same functionality as the OpenBSD library function + * reallocarray for those systems that don't have it. This function is the + * same as realloc, but takes the size arguments in the same form as calloc + * and checks for overflow so that the caller doesn't need to. * * The canonical version of this file is maintained in the rra-c-util package, * which can be found at . diff --git a/portable/setenv.c b/portable/setenv.c index 472282a..f1f6db4 100644 --- a/portable/setenv.c +++ b/portable/setenv.c @@ -26,6 +26,7 @@ * the system version. */ #if TESTING +# undef setenv # define setenv test_setenv int test_setenv(const char *, const char *, int); #endif @@ -34,29 +35,22 @@ int setenv(const char *name, const char *value, int overwrite) { char *envstring; - size_t size; + /* Do nothing if not overwriting and the variable is already set. */ if (!overwrite && getenv(name) != NULL) return 0; - /* - * Allocate memory for the environment string. We intentionally don't use - * the xmalloc family of allocation routines here, since the intention is - * to provide a replacement for the standard library function that sets - * errno and returns in the event of a memory allocation failure. - */ - size = strlen(name) + 1 + strlen(value) + 1; - envstring = malloc(size); - if (envstring == NULL) - return -1; - /* * Build the environment string and add it to the environment using * putenv. Systems without putenv lose, but XPG4 requires it. + * + * We intentionally don't use the xmalloc family of allocation routines + * here, since the intention is to provide a replacement for the standard + * library function that sets errno and returns in the event of a memory + * allocation failure. */ - strlcpy(envstring, name, size); - strlcat(envstring, "=", size); - strlcat(envstring, value, size); + if (asprintf(&envstring, "%s=%s", name, value) < 0) + return -1; return putenv(envstring); /* diff --git a/portable/snprintf.c b/portable/snprintf.c index c35ad80..9818acd 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -19,6 +19,8 @@ * conflicts with the system version. */ #if TESTING +# undef snprintf +# undef vsnprintf # define snprintf test_snprintf # define vsnprintf test_vsnprintf #endif diff --git a/portable/strlcat.c b/portable/strlcat.c index 9c8686d..613d3f2 100644 --- a/portable/strlcat.c +++ b/portable/strlcat.c @@ -31,6 +31,7 @@ * the system version. */ #if TESTING +# undef strlcat # define strlcat test_strlcat size_t test_strlcat(char *, const char *, size_t); #endif diff --git a/portable/strlcpy.c b/portable/strlcpy.c index 592e3ee..60fdab3 100644 --- a/portable/strlcpy.c +++ b/portable/strlcpy.c @@ -30,6 +30,7 @@ * the system version. */ #if TESTING +# undef strlcpy # define strlcpy test_strlcpy size_t test_strlcpy(char *, const char *, size_t); #endif diff --git a/portable/system.h b/portable/system.h index 544b2de..581e46c 100644 --- a/portable/system.h +++ b/portable/system.h @@ -136,10 +136,10 @@ extern void *reallocarray(void *, size_t, size_t); #if !HAVE_SETENV extern int setenv(const char *, const char *, int); #endif -#if !HAVE_STRLCAT +#if !HAVE_DECL_STRLCAT extern size_t strlcat(char *, const char *, size_t); #endif -#if !HAVE_STRLCPY +#if !HAVE_DECL_STRLCPY extern size_t strlcpy(char *, const char *, size_t); #endif -- cgit v1.2.3 From 128699d54becd0aa45f1fd43a0ab38642a58ce86 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 14:33:11 -0800 Subject: Remove remaining uses of strlcpy and strlcat --- Makefile.am | 6 ---- configure.ac | 4 +-- portable/strlcat.c | 52 ------------------------------- portable/strlcpy.c | 50 ----------------------------- tests/TESTS | 2 -- tests/portable/strlcat-t.c | 78 ---------------------------------------------- tests/portable/strlcat.c | 2 -- tests/portable/strlcpy-t.c | 70 ----------------------------------------- tests/portable/strlcpy.c | 2 -- 9 files changed, 2 insertions(+), 264 deletions(-) delete mode 100644 portable/strlcat.c delete mode 100644 portable/strlcpy.c delete mode 100644 tests/portable/strlcat-t.c delete mode 100644 tests/portable/strlcat.c delete mode 100644 tests/portable/strlcpy-t.c delete mode 100644 tests/portable/strlcpy.c (limited to 'portable') diff --git a/Makefile.am b/Makefile.am index 5c87639..214bb84 100644 --- a/Makefile.am +++ b/Makefile.am @@ -290,12 +290,6 @@ tests_portable_setenv_t_LDADD = tests/tap/libtap.a portable/libportable.a tests_portable_snprintf_t_SOURCES = tests/portable/snprintf-t.c \ tests/portable/snprintf.c tests_portable_snprintf_t_LDADD = tests/tap/libtap.a portable/libportable.a -tests_portable_strlcat_t_SOURCES = tests/portable/strlcat-t.c \ - tests/portable/strlcat.c -tests_portable_strlcat_t_LDADD = tests/tap/libtap.a portable/libportable.a -tests_portable_strlcpy_t_SOURCES = tests/portable/strlcpy-t.c \ - tests/portable/strlcpy.c -tests_portable_strlcpy_t_LDADD = tests/tap/libtap.a portable/libportable.a tests_util_messages_krb5_t_CPPFLAGS = $(KRB5_CPPFLAGS) tests_util_messages_krb5_t_LDFLAGS = $(KRB5_LDFLAGS) tests_util_messages_krb5_t_LDADD = tests/tap/libtap.a util/libutil.a \ diff --git a/configure.ac b/configure.ac index f4541e2..3b3c787 100644 --- a/configure.ac +++ b/configure.ac @@ -61,7 +61,7 @@ RRA_LIB_KRB5_RESTORE dnl Probe for properties of the C library. AC_HEADER_STDBOOL AC_CHECK_HEADERS([sys/bitypes.h sys/uio.h sys/time.h syslog.h]) -AC_CHECK_DECLS([snprintf, strlcat, strlcpy, vsnprintf]) +AC_CHECK_DECLS([snprintf, vsnprintf]) RRA_C_C99_VAMACROS RRA_C_GNU_VAMACROS AC_TYPE_LONG_LONG_INT @@ -69,7 +69,7 @@ AC_CHECK_TYPES([ssize_t], [], [], [#include ]) RRA_FUNC_SNPRINTF AC_CHECK_FUNCS([setrlimit]) -AC_REPLACE_FUNCS([asprintf mkstemp reallocarray setenv strlcat strlcpy]) +AC_REPLACE_FUNCS([asprintf mkstemp reallocarray setenv]) dnl Find a remctld binary for the test suite. AC_ARG_VAR([REMCTLD], [Path to the remctld binary]) diff --git a/portable/strlcat.c b/portable/strlcat.c deleted file mode 100644 index 613d3f2..0000000 --- a/portable/strlcat.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Replacement for a missing strlcat. - * - * Provides the same functionality as the *BSD function strlcat, originally - * developed by Todd Miller and Theo de Raadt. strlcat works similarly to - * strncat, except simpler. The result is always nul-terminated even if the - * source string is longer than the space remaining in the destination string, - * and the total space required is returned. The third argument is the total - * space available in the destination buffer, not just the amount of space - * remaining. - * - * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . - * - * Written by Russ Allbery - * - * 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. - */ - -#include -#include - -/* - * If we're running the test suite, rename strlcat to avoid conflicts with - * the system version. - */ -#if TESTING -# undef strlcat -# define strlcat test_strlcat -size_t test_strlcat(char *, const char *, size_t); -#endif - -size_t -strlcat(char *dst, const char *src, size_t size) -{ - size_t used, length, copy; - - used = strlen(dst); - length = strlen(src); - if (size > 0 && used < size - 1) { - copy = (length >= size - used) ? size - used - 1 : length; - memcpy(dst + used, src, copy); - dst[used + copy] = '\0'; - } - return used + length; -} diff --git a/portable/strlcpy.c b/portable/strlcpy.c deleted file mode 100644 index 60fdab3..0000000 --- a/portable/strlcpy.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Replacement for a missing strlcpy. - * - * Provides the same functionality as the *BSD function strlcpy, originally - * developed by Todd Miller and Theo de Raadt. strlcpy works similarly to - * strncpy, except saner and simpler. The result is always nul-terminated - * even if the source string is longer than the destination string, and the - * total space required is returned. The destination string is not nul-filled - * like strncpy does, just nul-terminated. - * - * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . - * - * Written by Russ Allbery - * - * 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. - */ - -#include -#include - -/* - * If we're running the test suite, rename strlcpy to avoid conflicts with - * the system version. - */ -#if TESTING -# undef strlcpy -# define strlcpy test_strlcpy -size_t test_strlcpy(char *, const char *, size_t); -#endif - -size_t -strlcpy(char *dst, const char *src, size_t size) -{ - size_t length, copy; - - length = strlen(src); - if (size > 0) { - copy = (length >= size) ? size - 1 : length; - memcpy(dst, src, copy); - dst[copy] = '\0'; - } - return length; -} diff --git a/tests/TESTS b/tests/TESTS index f78a477..76bd4ae 100644 --- a/tests/TESTS +++ b/tests/TESTS @@ -11,8 +11,6 @@ portable/asprintf portable/mkstemp portable/setenv portable/snprintf -portable/strlcat -portable/strlcpy server/admin server/backend server/keytab diff --git a/tests/portable/strlcat-t.c b/tests/portable/strlcat-t.c deleted file mode 100644 index 58aba58..0000000 --- a/tests/portable/strlcat-t.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * strlcat test suite. - * - * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . - * - * Written by Russ Allbery - * - * 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. - */ - -#include -#include - -#include - -size_t test_strlcat(char *, const char *, size_t); - - -int -main(void) -{ - char buffer[10] = ""; - - plan(27); - - is_int(3, test_strlcat(buffer, "foo", sizeof(buffer)), - "strlcat into empty buffer"); - is_string("foo", buffer, "...with right output"); - is_int(7, test_strlcat(buffer, " bar", sizeof(buffer)), - "...and append more"); - is_string("foo bar", buffer, "...and output is still correct"); - is_int(9, test_strlcat(buffer, "!!", sizeof(buffer)), - "...and append to buffer limit"); - is_string("foo bar!!", buffer, "...output is still correct"); - is_int(10, test_strlcat(buffer, "!", sizeof(buffer)), - "...append one more character"); - is_string("foo bar!!", buffer, "...and output didn't change"); - ok(buffer[9] == '\0', "...buffer still nul-terminated"); - buffer[0] = '\0'; - is_int(11, test_strlcat(buffer, "hello world", sizeof(buffer)), - "append single long string"); - is_string("hello wor", buffer, "...string truncates properly"); - ok(buffer[9] == '\0', "...buffer still nul-terminated"); - buffer[0] = '\0'; - is_int(7, test_strlcat(buffer, "sausage", 5), "lie about buffer length"); - is_string("saus", buffer, "...contents are correct"); - is_int(14, test_strlcat(buffer, "bacon eggs", sizeof(buffer)), - "...add more up to real size"); - is_string("sausbacon", buffer, "...and result is correct"); - - /* Make sure that with a size of 0, the destination isn't changed. */ - is_int(11, test_strlcat(buffer, "!!", 0), "no change with size of 0"); - is_string("sausbacon", buffer, "...and content is the same"); - - /* Now play with empty strings. */ - is_int(9, test_strlcat(buffer, "", 0), - "correct count when appending empty string"); - is_string("sausbacon", buffer, "...and contents are unchanged"); - buffer[0] = '\0'; - is_int(0, test_strlcat(buffer, "", sizeof(buffer)), - "correct count when appending empty string to empty buffer"); - is_string("", buffer, "...and buffer content is correct"); - is_int(3, test_strlcat(buffer, "foo", 2), "append to length 2 buffer"); - is_string("f", buffer, "...and got only a single character"); - ok(buffer[1] == '\0', "...and buffer is still nul-terminated"); - is_int(1, test_strlcat(buffer, "", sizeof(buffer)), - "append an empty string"); - ok(buffer[1] == '\0', "...and buffer is still nul-terminated"); - - return 0; -} diff --git a/tests/portable/strlcat.c b/tests/portable/strlcat.c deleted file mode 100644 index 8983bd8..0000000 --- a/tests/portable/strlcat.c +++ /dev/null @@ -1,2 +0,0 @@ -#define TESTING 1 -#include diff --git a/tests/portable/strlcpy-t.c b/tests/portable/strlcpy-t.c deleted file mode 100644 index 6652a7c..0000000 --- a/tests/portable/strlcpy-t.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * strlcpy test suite. - * - * The canonical version of this file is maintained in the rra-c-util package, - * which can be found at . - * - * Written by Russ Allbery - * - * 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. - */ - -#include -#include - -#include - -size_t test_strlcpy(char *, const char *, size_t); - - -int -main(void) -{ - char buffer[10]; - - plan(23); - - is_int(3, test_strlcpy(buffer, "foo", sizeof(buffer)), "simple strlcpy"); - is_string("foo", buffer, "...result is correct"); - is_int(9, test_strlcpy(buffer, "hello wor", sizeof(buffer)), - "strlcpy exact length of buffer"); - is_string("hello wor", buffer, "...result is correct"); - is_int(10, test_strlcpy(buffer, "world hell", sizeof(buffer)), - "strlcpy one more than buffer length"); - is_string("world hel", buffer, "...result is correct"); - ok(buffer[9] == '\0', "...buffer is nul-terminated"); - is_int(11, test_strlcpy(buffer, "hello world", sizeof(buffer)), - "strlcpy more than buffer length"); - is_string("hello wor", buffer, "...result is correct"); - ok(buffer[9] == '\0', "...buffer is nul-terminated"); - - /* Make sure that with a size of 0, the destination isn't changed. */ - is_int(3, test_strlcpy(buffer, "foo", 0), "buffer unchanged if size 0"); - is_string("hello wor", buffer, "...contents still the same"); - - /* Now play with empty strings. */ - is_int(0, test_strlcpy(buffer, "", 0), "copy empty string with size 0"); - is_string("hello wor", buffer, "...buffer unchanged"); - is_int(0, test_strlcpy(buffer, "", sizeof(buffer)), - "copy empty string into full buffer"); - is_string("", buffer, "...buffer now empty string"); - is_int(3, test_strlcpy(buffer, "foo", 2), - "copy string into buffer of size 2"); - is_string("f", buffer, "...got one character"); - ok(buffer[1] == '\0', "...buffer is nul-terminated"); - is_int(0, test_strlcpy(buffer, "", 1), - "copy empty string into buffer of size 1"); - ok(buffer[0] == '\0', "...buffer is empty string"); - - /* Finally, check using strlcpy as strlen. */ - is_int(3, test_strlcpy(NULL, "foo", 0), "use strlcpy as strlen"); - is_int(11, test_strlcpy(NULL, "hello world", 0), "...again"); - - return 0; -} diff --git a/tests/portable/strlcpy.c b/tests/portable/strlcpy.c deleted file mode 100644 index d444595..0000000 --- a/tests/portable/strlcpy.c +++ /dev/null @@ -1,2 +0,0 @@ -#define TESTING 1 -#include -- cgit v1.2.3