]> Savannah Git Hosting - gnulib.git/commit
random_r: do not crash if state is unaligned
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Jun 2018 19:28:34 +0000 (12:28 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Jun 2018 19:29:04 +0000 (12:29 -0700)
commit6979c258b34d3a4203c138192ffa37429ee1a753
tree3bbd8a9dd16981913f9a5e08bb519b0faf9580f3
parentdc4b9a1f9ab1199cef0dbe53738e78b307baa5ee
random_r: do not crash if state is unaligned

Problem reported by Bruce Korb in:
https://lists.gnu.org/r/bug-gnulib/2018-06/msg00030.html
I reproduced the crash on 32-bit sparc with Oracle Studio 12.6
with 'cc -O2 -xmemalign=8s'.
* lib/random_r.c: Include string.h, for memcpy.
(get_int32, set_int32): New functions.
(__srandom_r, __initstate_r, __setstate_r, __random_r):
Use them to avoid assumption that state pointer is aligned.
(__random_r): Avoid integer overflow if INT_MAX == UINT32_MAX.
* tests/test-random_r.c (test_failed): New function.
(main): Use it, to test for alignment bugs.
ChangeLog
lib/random_r.c
tests/test-random_r.c