Date: Sat, 21 May 2016 17:38:44 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300376 - head/sys/compat/ndis Message-ID: <201605211738.u4LHciji025148@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Sat May 21 17:38:43 2016 New Revision: 300376 URL: https://svnweb.freebsd.org/changeset/base/300376 Log: ndis(4): Better mimic the behavior of rand() on Windows. In ndis(4) we expose a rand() function that was constantly reseeding with a time depending function every time it was called. This essentially broke the reasoning behind seeding, and rendered srand() a no-op. Keep it simple, just use random() and srandom() as it's meant to work. It would have been tempting to just go for arc4random() but we want to mimic Microsoft, and we don't need crypto-grade randomness here. PR: 209616 MFC after: 2 weeks Modified: head/sys/compat/ndis/subr_ntoskrnl.c Modified: head/sys/compat/ndis/subr_ntoskrnl.c ============================================================================== --- head/sys/compat/ndis/subr_ntoskrnl.c Sat May 21 16:52:38 2016 (r300375) +++ head/sys/compat/ndis/subr_ntoskrnl.c Sat May 21 17:38:43 2016 (r300376) @@ -3188,17 +3188,14 @@ atol(str) static int rand(void) { - struct timeval tv; - microtime(&tv); - srandom(tv.tv_usec); - return ((int)random()); + return (random()); } static void -srand(seed) - unsigned int seed; +srand(unsigned int seed) { + srandom(seed); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605211738.u4LHciji025148>