[PATCH 1/2] stdlib: Fix unintended change to the random_r implementation

Andreas K. Huettel dilfridge@gentoo.org
Mon Jan 20 21:17:35 GMT 2025


Am Montag, 20. Januar 2025, 21:06:43 Mitteleuropäische Normalzeit schrieb Florian Weimer:
> Commit d5bceac99d24af1131b90027dab267e437b65cd1 changed the sequence
> of random numbers.  This was completely unintended.  The statistical
> properties of the new sequences are unclear, so restore the old
> behavior.

Obviously this should still go in for the release... -a

> 
> Fixes commit d5bceac99d24af1131b90027dab267e437b65cd1 ("stdlib:
> random_r: fix unaligned access in initstate and initstate_r
> [BZ #30584]").
> ---
>  stdlib/random_r.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/stdlib/random_r.c b/stdlib/random_r.c
> index 605e96983c..b49f03f5be 100644
> --- a/stdlib/random_r.c
> +++ b/stdlib/random_r.c
> @@ -390,9 +390,10 @@ __random_r (struct random_data *buf, int32_t *result)
>        int32_t *end_ptr = buf->end_ptr;
>        uint32_t val;
>  
> -      val = read_state (rptr, 0);
> -      int32_t t = read_state (fptr, 0);
> -      write_state (fptr, 0, t + val);
> +      /* Avoid integer overflow with uint32_t arihmetic.  */
> +      val = read_state (fptr, 0);
> +      val += read_state (rptr, 0);
> +      write_state (fptr, 0, val);
>        /* Chucking least random bit.  */
>        *result = val >> 1;
>        ++fptr;
> 
> base-commit: a3131e71cf65c0c28869824de9b1b1fab363882c
> 


-- 
Andreas K. Hüttel
dilfridge@gentoo.org
Gentoo Linux developer
(council, toolchain, base-system, perl, libreoffice)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 981 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250120/8cef208c/attachment.sig>


More information about the Libc-alpha mailing list