From 63a76f57ef1ca4f60bf7c7485abd6579ca91b2ac Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sat, 8 May 2004 19:42:36 +0000 Subject: unless specifically requested by setting the seed, use arc4random(); otto ok --- bin/ksh/var.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bin/ksh') diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 8d3eacb37d2..989542aa044 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.16 2003/08/05 20:52:27 millert Exp $ */ +/* $OpenBSD: var.c,v 1.17 2004/05/08 19:42:35 deraadt Exp $ */ #include "sh.h" #include "ksh_time.h" @@ -882,6 +882,12 @@ makenv() return (char **) XPclose(env); } +/* + * Someone has set the srand() value, therefore from now on + * we return values from rand() instead of arc4random() + */ +int use_rand = 0; + /* * Called after a fork in parent to bump the random number generator. * Done to ensure children will not get the same random number sequence @@ -890,7 +896,8 @@ makenv() void change_random() { - rand(); + if (use_rand) + rand(); } /* @@ -943,7 +950,10 @@ getspec(vp) break; case V_RANDOM: vp->flag &= ~SPECIAL; - setint(vp, (long) (rand() & 0x7fff)); + if (use_rand) + setint(vp, (long) (rand() & 0x7fff)); + else + setint(vp, (long) (arc4random() & 0x7fff)); vp->flag |= SPECIAL; break; #endif /* KSH */ @@ -1046,6 +1056,7 @@ setspec(vp) case V_RANDOM: vp->flag &= ~SPECIAL; srand((unsigned int)intval(vp)); + use_rand = 1; vp->flag |= SPECIAL; break; case V_SECONDS: -- cgit v1.2.3