From 7a939386875c26e936f0e07630ce80cff52ea64b Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Thu, 25 May 2017 18:21:57 +0200 Subject: [PATCH] Start using arc4random_buf with BSD and libbsd --- expat/Makefile.in | 2 +- expat/configure.ac | 20 ++++++++++++++++++++ expat/lib/xmlparse.c | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/expat/Makefile.in b/expat/Makefile.in index bbf461ae..f4cf3284 100644 --- a/expat/Makefile.in +++ b/expat/Makefile.in @@ -124,7 +124,7 @@ LTFLAGS = --verbose COMPILE = $(CC) $(INCLUDES) $(CFLAGS) $(DEFS) $(CPPFLAGS) CXXCOMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS) $(DEFS) $(CPPFLAGS) LTCOMPILE = $(LIBTOOL) $(LTFLAGS) --mode=compile $(COMPILE) -LINK_LIB = $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) -no-undefined $(VSNFLAG) -rpath $(libdir) $(LDFLAGS) -o $@ +LINK_LIB = $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) -no-undefined $(VSNFLAG) -rpath $(libdir) $(LDFLAGS) @LIBS@ -o $@ LINK_EXE = $(LIBTOOL) $(LTFLAGS) --mode=link $(COMPILE) $(LDFLAGS) -o $@ LINK_CXX_EXE = $(LIBTOOL) $(LTFLAGS) --mode=link $(CXXCOMPILE) $(LDFLAGS) -o $@ diff --git a/expat/configure.ac b/expat/configure.ac index 5ae840fe..199bf474 100644 --- a/expat/configure.ac +++ b/expat/configure.ac @@ -100,6 +100,26 @@ AC_TYPE_SIZE_T AC_CHECK_FUNCS(memmove bcopy) +AC_CHECK_LIB([bsd], [arc4random_buf]) +AC_MSG_CHECKING([for arc4random_buf (BSD or libbsd)]) +AC_LINK_IFELSE([AC_LANG_SOURCE([ + #include /* for arc4random_buf on BSD, for NULL */ + #if defined(HAVE_LIBBSD) + # include + #endif + int main() { + arc4random_buf(NULL, 0U); + return 0; + } +])], [ + AC_DEFINE([HAVE_ARC4RANDOM_BUF], [1], + [Define to 1 if you have the `arc4random_buf' function.]) + AC_MSG_RESULT([yes]) +], [ + AC_MSG_RESULT([no]) +]) + + AC_MSG_CHECKING([for getrandom (Linux 3.17+, glibc 2.25+)]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([ #include /* for NULL */ diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c index af3c7890..aa7b7c31 100644 --- a/expat/lib/xmlparse.c +++ b/expat/lib/xmlparse.c @@ -779,6 +779,10 @@ gather_time_entropy(void) #endif } +#if defined(HAVE_ARC4RANDOM_BUF) && defined(HAVE_LIBBSD) +# include +#endif + static unsigned long generate_hash_secret_salt(XML_Parser parser) { @@ -790,7 +794,7 @@ generate_hash_secret_salt(XML_Parser parser) # define PARSER_CAST(p) (p) #endif -#ifdef __CloudABI__ +#if defined(HAVE_ARC4RANDOM_BUF) || defined(__CloudABI__) unsigned long entropy; (void)parser; (void)gather_time_entropy;