arc4random does not reseed after using fork()
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Jan 29 12:46:07 GMT 2024
Hi Johnothan,
On Jan 26 22:06, Johnothan King via Cygwin wrote:
> Hello,
>
> While testing ksh93u+m's recently added SRANDOM variable[1], I have
> discovered a bug in Cygwin's arc4random function. After using fork(),
> arc4random does not reseed itself, which causes the results to become
> predictable[2]. Below is a test case C program exhibiting the bug:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/wait.h>
> int main(void)
> {
> pid_t child = fork();
> if(child==0)
> {
> printf("%u %u %u\n", arc4random(), arc4random(), arc4random());
> return 0;
> }
> else if(child==-1)
> return 1;
> waitpid(child, NULL, 0);
> printf("%u %u %u\n", arc4random(), arc4random(), arc4random());
> return 0;
> }
Thanks for the testcase. I fixed that for Cygwin 3.5. Please
try the latest test release cygwin-3.5.0-0.617.g030a762535c1,
which should be finished building in about an hour.
Thanks,
Corinna
More information about the Cygwin
mailing list