diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-08 19:42:36 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-05-08 19:42:36 +0000 |
commit | 63a76f57ef1ca4f60bf7c7485abd6579ca91b2ac (patch) | |
tree | fbd62000b77463a9e46d3790e9f38c24faa1116d /bin/ksh | |
parent | 3287273117ca2657bfbd79538b58e9d07dd6ab06 (diff) |
unless specifically requested by setting the seed, use arc4random(); otto ok
Diffstat (limited to 'bin/ksh')
-rw-r--r-- | bin/ksh/var.c | 17 |
1 files changed, 14 insertions, 3 deletions
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" @@ -883,6 +883,12 @@ makenv() } /* + * 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 * if the parent doesn't use $RANDOM. @@ -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: |