libxml's use of random numbers doesn't exactly need to be strong itself,
but extra calls to arc4random help other things on the system, and this
gets rid of some APIWARN from programs that link against it, making it
easier to identify use of unsafe randomness in the many programs which
depend on libxml.

There are no new failures in regression tests with this diff. Does it
look sane? Any comments/objections/OKs?

Index: Makefile
===================================================================
RCS file: /cvs/ports/textproc/libxml/Makefile,v
retrieving revision 1.153
diff -u -p -r1.153 Makefile
--- Makefile    12 May 2014 07:48:35 -0000      1.153
+++ Makefile    29 May 2014 10:59:56 -0000
@@ -23,7 +23,8 @@ WANTLIB=              m z
 
 MODULES=               converters/libiconv
 
-CONFIGURE_STYLE=       gnu
+CONFIGURE_STYLE=       autoconf
+AUTOCONF_VERSION=      2.69
 CONFIGURE_ARGS+=       ${CONFIGURE_SHARED} \
                        --enable-static \
                        --with-html-dir="${PREFIX}/share/doc" \
Index: patches/patch-configure_in
===================================================================
RCS file: patches/patch-configure_in
diff -N patches/patch-configure_in
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-configure_in  29 May 2014 10:59:56 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- configure.in.orig  Thu May 29 11:37:41 2014
++++ configure.in       Thu May 29 11:37:49 2014
+@@ -516,7 +516,7 @@ AC_CHECK_FUNCS(strdup strndup strerror)
+ AC_CHECK_FUNCS(finite isnand fp_class class fpclass)
+ AC_CHECK_FUNCS(strftime localtime gettimeofday ftime)
+ AC_CHECK_FUNCS(stat _stat signal)
+-AC_CHECK_FUNCS(rand rand_r srand time)
++AC_CHECK_FUNCS(arc4random rand rand_r srand time)
+ AC_CHECK_FUNCS(isascii mmap munmap putenv)
+ 
+ AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */
Index: patches/patch-dict_c
===================================================================
RCS file: patches/patch-dict_c
diff -N patches/patch-dict_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-dict_c        29 May 2014 10:59:56 -0000
@@ -0,0 +1,42 @@
+$OpenBSD$
+--- dict.c.orig        Thu May 29 11:36:20 2014
++++ dict.c     Thu May 29 11:42:40 2014
+@@ -139,7 +139,7 @@ static xmlRMutexPtr xmlDictMutex = NULL;
+ static int xmlDictInitialized = 0;
+ 
+ #ifdef DICT_RANDOMIZATION
+-#ifdef HAVE_RAND_R
++#if defined(HAVE_RAND_R) && !defined(HAVE_ARC4RANDOM)
+ /*
+  * Internal data for random function, protected by xmlDictMutex
+  */
+@@ -180,7 +180,7 @@ int __xmlInitializeDict(void) {
+         return(0);
+     xmlRMutexLock(xmlDictMutex);
+ 
+-#ifdef DICT_RANDOMIZATION
++#if defined(DICT_RANDOMIZATION) && !defined(HAVE_ARC4RANDOM)
+ #ifdef HAVE_RAND_R
+     rand_seed = time(NULL);
+     rand_r(& rand_seed);
+@@ -200,13 +200,17 @@ int __xmlRandom(void) {
+     if (xmlDictInitialized == 0)
+         __xmlInitializeDict();
+ 
++#ifdef HAVE_ARC4RANDOM
++    ret = arc4random();
++#else
+     xmlRMutexLock(xmlDictMutex);
+-#ifdef HAVE_RAND_R
++#  ifdef HAVE_RAND_R
+     ret = rand_r(& rand_seed);
+-#else
++#  else
+     ret = rand();
+-#endif
++#  endif
+     xmlRMutexUnlock(xmlDictMutex);
++#endif
+     return(ret);
+ }
+ #endif

Reply via email to