From: Bruno Haible Date: Fri, 10 Nov 2023 15:46:17 +0000 (+0100) Subject: random: Fix multithread-safety bug in general. X-Git-Tag: v1.0~612 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=53483b103f8d733df604e03f5260486ebf1a4496;p=gnulib.git random: Fix multithread-safety bug in general. * m4/random.m4 (gl_FUNC_RANDOM): Override also macOS, FreeBSD, Solaris, Cygwin, Haiku. * doc/posix-functions/random.texi: Mention the wider scope of the multithread-safety bug. --- diff --git a/ChangeLog b/ChangeLog index 5c92da54ec..d38e5b5665 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-11-10 Bruno Haible + + random: Fix multithread-safety bug in general. + * m4/random.m4 (gl_FUNC_RANDOM): Override also macOS, FreeBSD, Solaris, + Cygwin, Haiku. + * doc/posix-functions/random.texi: Mention the wider scope of the + multithread-safety bug. + 2023-11-09 Bruno Haible sigsegv: Improve port to CHERI. diff --git a/doc/posix-functions/random.texi b/doc/posix-functions/random.texi index e0bb8e76bc..84cacbe8b5 100644 --- a/doc/posix-functions/random.texi +++ b/doc/posix-functions/random.texi @@ -15,8 +15,8 @@ mingw, MSVC 14. This function is only defined as an inline function on some platforms: Android 4.4. @item -This function crashes when used in multithreaded programs on some platforms: -CheriBSD. +This function is not multithread-safe on some platforms: +macOS 12.5, FreeBSD 13.2, Solaris 11.4, Cygwin 3.4.6, Haiku. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/random.m4 b/m4/random.m4 index 69bac2459a..4e4f01b8ed 100644 --- a/m4/random.m4 +++ b/m4/random.m4 @@ -1,4 +1,4 @@ -# random.m4 serial 7 +# random.m4 serial 8 dnl Copyright (C) 2012-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -44,10 +44,13 @@ AC_DEFUN([gl_FUNC_RANDOM], future*) REPLACE_SETSTATE=1 ;; esac fi - dnl On CheriBSD, random() lacks locking, leading to an out-of-bounds read - dnl inside random_r. + dnl On several platforms, random() is not multithread-safe. if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no \ - || case "$host" in aarch64c-*-freebsd*) true;; *) false;; esac; then + || case "$host_os" in \ + darwin* | freebsd* | solaris* | cygwin* | haiku*) true ;; \ + *) false ;; \ + esac + then dnl In order to define initstate or setstate, we need to define all the dnl functions at once. REPLACE_RANDOM=1