NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/25367: arc4random state is shared across forks



The following reply was made to PR lib/25367; it has been noted by GNATS.

From: Roy Marples <roy%marples.name@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: apb%cequrux.com@localhost, David Laight <david%l8s.co.uk@localhost>, David 
Holland
 <dholland-bugs%netbsd.org@localhost>
Subject: Re: lib/25367: arc4random state is shared across forks
Date: Sun, 25 May 2014 08:30:35 +0100

 --=_78a787e1cccc4ca0768aab6f423d85a8
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain; charset=UTF-8;
  format=flowed
 
 Hi
 
 I bumped into this as well.
 I looked over the FreeBSD thread regarding potential speed issues and 
 despite any concerns they have actually merged the change in.
 Attached is a patch to -current which does two things.
 
 1) Re-stirs if the pid changes
 2) Re-stirs after swallowing 1600000 bytes (which also addresses 
 PR/45952)
 
 I've been running this on my laptop for a while with great success and 
 unless anyone objects I'll commit it shortly.
 
 Thanks
 
 Roy
 
 --=_78a787e1cccc4ca0768aab6f423d85a8
 Content-Transfer-Encoding: base64
 Content-Type: text/x-diff;
  name=arc4random-pid.diff
 Content-Disposition: attachment;
  filename=arc4random-pid.diff;
  size=3981
 
 PyB0ZXN0Cj8gdGVzdC5jCkluZGV4OiBnZW4vYXJjNHJhbmRvbS5jCj09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNTIGZp
 bGU6IC9jdnNyb290L3NyYy9saWIvbGliYy9nZW4vYXJjNHJhbmRvbS5jLHYKcmV0cmlldmluZyBy
 ZXZpc2lvbiAxLjIxCmRpZmYgLXUgLXAgLXIxLjIxIGFyYzRyYW5kb20uYwotLS0gZ2VuL2FyYzRy
 YW5kb20uYwkxNyBPY3QgMjAxMyAyMzo1NjoxNyAtMDAwMAkxLjIxCisrKyBnZW4vYXJjNHJhbmRv
 bS5jCTI0IE1heSAyMD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