Skip to content

Commit

Permalink
Improve and simplify function and header detection logic.
Browse files Browse the repository at this point in the history
Simplify autoconf checks by using AC_CHECK_FUNCS/HEADERS.
Clarify some ambiguous dependencies around strnlen/strndup.
Unconditionally enable pidwraptest for all arc4random implementations.
Remove HAVE_VASPRINTF conditional, since asprintf requires vasprintf.

ok @doug
  • Loading branch information
busterb committed Oct 31, 2014
1 parent 727bccd commit a4cc953
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 112 deletions.
2 changes: 1 addition & 1 deletion apps/Makefile.am.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ openssl_LDADD += $(top_builddir)/crypto/libcrypto.la
openssl_SOURCES =
noinst_HEADERS =

if NO_STRTONUM
if !HAVE_STRTONUM
openssl_SOURCES += strtonum.c
endif
97 changes: 21 additions & 76 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -58,75 +58,26 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
)
CFLAGS="$save_cflags $AM_CFLAGS"

AC_CHECK_FUNC(strlcpy,
AM_CONDITIONAL(NO_STRLCPY, false),
AC_DEFINE(NO_STRLCPY)
AM_CONDITIONAL(NO_STRLCPY, true))

AC_CHECK_FUNC(strlcat,
AM_CONDITIONAL(NO_STRLCAT, false),
AC_DEFINE(NO_STRLCAT)
AM_CONDITIONAL(NO_STRLCAT, true))

AC_CHECK_FUNC(strndup,
AM_CONDITIONAL(NO_STRNDUP, false),
AC_DEFINE(NO_STRNDUP)
AM_CONDITIONAL(NO_STRNDUP, true))

AC_CHECK_FUNC(strnlen,
AM_CONDITIONAL(NO_STRNLEN, false),
AC_DEFINE(NO_STRNLEN)
AM_CONDITIONAL(NO_STRNLEN, true))

AC_CHECK_FUNC(asprintf,
AM_CONDITIONAL(NO_ASPRINTF, false),
AC_DEFINE(NO_ASPRINTF)
AM_CONDITIONAL(NO_ASPRINTF, true))

AC_CHECK_FUNC(reallocarray,
AM_CONDITIONAL(NO_REALLOCARRAY, false),
AC_DEFINE(NO_REALLOCARRAY)
AM_CONDITIONAL(NO_REALLOCARRAY, true))

AC_CHECK_FUNC(timingsafe_bcmp,
AM_CONDITIONAL(NO_TIMINGSAFE_BCMP, false),
AC_DEFINE(NO_TIMINGSAFE_BCMP)
AM_CONDITIONAL(NO_TIMINGSAFE_BCMP, true))

AC_CHECK_FUNC(timingsafe_memcmp,
AM_CONDITIONAL(NO_TIMINGSAFE_MEMCMP, false),
AC_DEFINE(NO_TIMINGSAFE_MEMCMP)
AM_CONDITIONAL(NO_TIMINGSAFE_MEMCMP, true))

AC_CHECK_FUNC(arc4random_buf,
AM_CONDITIONAL(NO_ARC4RANDOM_BUF, false),
AC_DEFINE(NO_ARC4RANDOM_BUF)
AM_CONDITIONAL(NO_ARC4RANDOM_BUF, true))

AC_CHECK_FUNC(getentropy,
AM_CONDITIONAL(NO_GETENTROPY, false),
AC_DEFINE(NO_GETENTROPY)
AM_CONDITIONAL(NO_GETENTROPY, true))

AC_CHECK_FUNC(issetugid,
AM_CONDITIONAL(NO_ISSETUGID, false),
AC_DEFINE(NO_ISSETUGID)
AM_CONDITIONAL(NO_ISSETUGID, true))

AC_CHECK_FUNC(strtonum,
AM_CONDITIONAL(NO_STRTONUM, false),
AC_DEFINE(NO_STRTONUM)
AM_CONDITIONAL(NO_STRTONUM, true))

AC_CHECK_FUNC(memmem,
AM_CONDITIONAL(NO_MEMMEM, false),
AC_DEFINE(NO_MEMMEM)
AM_CONDITIONAL(NO_MEMMEM, true))

AC_CHECK_FUNC(explicit_bzero,
AM_CONDITIONAL(NO_EXPLICIT_BZERO, false),
AC_DEFINE(NO_EXPLICIT_BZERO)
AM_CONDITIONAL(NO_EXPLICIT_BZERO, true))
AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval])
AC_CHECK_FUNCS([getentropy issetugid memmem reallocarray])
AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])

# Share test results with automake
AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
AM_CONDITIONAL([HAVE_ISSETUGID], [test "x$ac_cv_func_issetugid" = xyes])
AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])

AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Expand All @@ -153,13 +104,7 @@ if test "x$ac_cv_have___va_copy" = "xyes" ; then
AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
fi

AC_CHECK_FUNC(getauxval, AC_DEFINE(HAVE_GETAUXVAL))

AC_CHECK_FUNC(funopen, AC_DEFINE(HAVE_FUNOPEN))

AC_CHECK_HEADER(sys/sysctl.h, AC_DEFINE(HAVE_SYS_SYSCTL_H))

AC_CHECK_HEADER(err.h, AC_DEFINE(HAVE_ERR_H))
AC_CHECK_HEADERS([sys/sysctl.h err.h])

AC_ARG_WITH([openssldir],
AS_HELP_STRING([--with-openssldir], [Set the default openssl directory]),
Expand Down
25 changes: 13 additions & 12 deletions crypto/Makefile.am.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la
libcompatnoopt_la_CFLAGS = -O0
libcompatnoopt_la_SOURCES =

if NO_EXPLICIT_BZERO
if !HAVE_EXPLICIT_BZERO
libcompatnoopt_la_SOURCES += compat/explicit_bzero.c
endif

Expand All @@ -25,41 +25,42 @@ libcompat_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS)
libcompat_la_SOURCES =
libcompat_la_LIBADD = $(PLATFORM_LDADD)

if NO_STRLCAT
if !HAVE_STRLCAT
libcompat_la_SOURCES += compat/strlcat.c
endif

if NO_STRLCPY
if !HAVE_STRLCPY
libcompat_la_SOURCES += compat/strlcpy.c
endif

if NO_STRNDUP
if !HAVE_STRNDUP
libcompat_la_SOURCES += compat/strndup.c
if NO_STRNLEN
# the only user of strnlen is strndup, so only build it if needed
if !HAVE_STRNLEN
libcompat_la_SOURCES += compat/strnlen.c
endif
endif

if NO_ASPRINTF
if !HAVE_ASPRINTF
libcompat_la_SOURCES += compat/bsd-asprintf.c
endif

if NO_REALLOCARRAY
if !HAVE_REALLOCARRAY
libcompat_la_SOURCES += compat/reallocarray.c
endif

if NO_TIMINGSAFE_MEMCMP
if !HAVE_TIMINGSAFE_MEMCMP
libcompat_la_SOURCES += compat/timingsafe_memcmp.c
endif

if NO_TIMINGSAFE_BCMP
if !HAVE_TIMINGSAFE_BCMP
libcompat_la_SOURCES += compat/timingsafe_bcmp.c
endif

if NO_ARC4RANDOM_BUF
if !HAVE_ARC4RANDOM_BUF
libcompat_la_SOURCES += compat/arc4random.c

if NO_GETENTROPY
if !HAVE_GETENTROPY
if HOST_LINUX
libcompat_la_SOURCES += compat/getentropy_linux.c
endif
Expand All @@ -76,7 +77,7 @@ endif

endif

if NO_ISSETUGID
if !HAVE_ISSETUGID
if HOST_LINUX
libcompat_la_SOURCES += compat/issetugid_linux.c
endif
Expand Down
4 changes: 1 addition & 3 deletions crypto/compat/bsd-asprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef HAVE_VASPRINTF
#ifndef HAVE_ASPRINTF

#include <errno.h>
#include <limits.h> /* for INT_MAX */
Expand Down Expand Up @@ -80,9 +80,7 @@ vasprintf(char **str, const char *fmt, va_list ap)
errno = ENOMEM;
return (-1);
}
#endif

#ifndef HAVE_ASPRINTF
int asprintf(char **str, const char *fmt, ...)
{
va_list ap;
Expand Down
2 changes: 1 addition & 1 deletion include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef LIBCRYPTOCOMPAT_STDIO_H
#define LIBCRYPTOCOMPAT_STDIO_H

#ifdef NO_ASPRINTF
#ifndef HAVE_ASPRINTF
#include <stdarg.h>
int vasprintf(char **str, const char *fmt, va_list ap);
int asprintf(char **str, const char *fmt, ...);
Expand Down
6 changes: 3 additions & 3 deletions include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#include <sys/time.h>
#include <stdint.h>

#ifdef NO_ARC4RANDOM_BUF
#ifndef HAVE_ARC4RANDOM_BUF
uint32_t arc4random(void);
void arc4random_buf(void *_buf, size_t n);
#endif

#ifdef NO_REALLOCARRAY
#ifndef HAVE_REALLOCARRAY
void *reallocarray(void *, size_t, size_t);
#endif

#ifdef NO_STRTONUM
#ifndef HAVE_STRTONUM
long long strtonum(const char *nptr, long long minval,
long long maxval, const char **errstr);
#endif
Expand Down
17 changes: 9 additions & 8 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
#include <strings.h>
#endif

#ifdef NO_STRLCPY
#ifndef HAVE_STRLCPY
size_t strlcpy(char *dst, const char *src, size_t siz);
#endif

#ifdef NO_STRLCAT
#ifndef HAVE_STRLCAT
size_t strlcat(char *dst, const char *src, size_t siz);
#endif

#ifdef NO_STRNDUP
#ifndef HAVE_STRNDUP
char * strndup(const char *str, size_t maxlen);
#ifdef NO_STRNLEN
/* the only user of strnlen is strndup, so only build it if needed */
#ifndef HAVE_STRNLEN
size_t strnlen(const char *str, size_t maxlen);
#endif
#endif

#ifdef NO_EXPLICIT_BZERO
#ifndef HAVE_EXPLICIT_BZERO
void explicit_bzero(void *, size_t);
#endif

#ifdef NO_TIMINGSAFE_BCMP
#ifndef HAVE_TIMINGSAFE_BCMP
int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
#endif

#ifdef NO_TIMINGSAFE_MEMCMP
#ifndef HAVE_TIMINGSAFE_MEMCMP
int timingsafe_memcmp(const void *b1, const void *b2, size_t len);
#endif

#ifdef NO_MEMMEM
#ifndef HAVE_MEMMEM
void * memmem(const void *big, size_t big_len, const void *little,
size_t little_len);
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#ifndef LIBCRYPTOCOMPAT_UNISTD_H
#define LIBCRYPTOCOMPAT_UNISTD_H

#ifdef NO_GETENTROPY
#ifndef HAVE_GETENTROPY
int getentropy(void *buf, size_t buflen);
#endif

#ifdef NO_ISSETUGID
#ifndef HAVE_ISSETUGID
int issetugid(void);
#endif

Expand Down
4 changes: 0 additions & 4 deletions tests/Makefile.am.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ LDADD += $(top_builddir)/crypto/libcrypto.la
TESTS =
check_PROGRAMS =
EXTRA_DIST =

if !NO_ARC4RANDOM_BUF
TESTS += pidwraptest.sh
endif
3 changes: 1 addition & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ test_drivers=(
# disabled by-default tests
tests_disabled=(
biotest
pidwraptest
)
$CP $libc_src/string/memmem.c tests/
(cd tests
Expand All @@ -319,7 +318,7 @@ $CP $libc_src/string/memmem.c tests/
echo "check_PROGRAMS += $TEST" >> Makefile.am
echo "${TEST}_SOURCES = $i" >> Makefile.am
done
echo "if NO_MEMMEM" >> Makefile.am
echo "if !HAVE_MEMMEM" >> Makefile.am
echo "explicit_bzero_SOURCES += memmem.c" >> Makefile.am
echo "endif" >> Makefile.am
)
Expand Down

0 comments on commit a4cc953

Please sign in to comment.