summaryrefslogtreecommitdiff
path: root/libgcompat/random_r.c
AgeCommit message (Collapse)AuthorFilesLines
2022-10-06random_r: fix null dereference when passed uninitialized bufGeorge Matsumura1-37/+39
Previously, initstate_r would attempt to pack the n, i, and j values into the state array pointed to by the x member value of buf, which would cause access to an invalid region of memory when buf was uninitialized. However, packing the values into the state array was required when buf was initialized, as otherwise the values of n, i, and j would not be saved. Critically, initstate_r had no means by which to distinguish between an uninitialized and initialized buf struct. This change makes the random_r and srandom_r do the packing and unpacking of the n, i, and j values instead. This does lead to a somewhat more inefficient algorithm, but preserves compatibility in case setstate_r is passed a state array that was initialized with the normal initstate function. Signed-off-by: George Matsumura <gm960420@ohio.edu>
2021-12-19random_r: set `x` before calling savestate_r A. Wilcox1-1/+1
Prevents segfault when calling initstate_r.
2021-06-25random_r: Add reentrant random functions from LSBGeorge Matsumura1-0/+157
This adds random_r() and associated functions, mostly adapted from musl's implementation of random(). Signed-off-by: George Matsumura <gm960420@ohio.edu>