always use rand(3) on platforms without arc4random(3) and seed it
This commit is contained in:
parent
8266c126ac
commit
820f4b1de1
7
main.c
7
main.c
@ -1,4 +1,4 @@
|
||||
/** $MirOS: src/bin/mksh/main.c,v 1.1 2005/05/23 03:06:08 tg Exp $ */
|
||||
/** $MirOS: src/bin/mksh/main.c,v 1.2 2005/05/23 14:22:03 tg Exp $ */
|
||||
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
|
||||
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
|
||||
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
|
||||
@ -10,7 +10,7 @@
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.1 2005/05/23 03:06:08 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.2 2005/05/23 14:22:03 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -201,6 +201,9 @@ main(int argc, char *argv[])
|
||||
setstr(pwd_v, current_wd, KSH_RETURN_ERROR);
|
||||
}
|
||||
ppid = getppid();
|
||||
#if !defined(__gnu_linux__) && !defined(__INTERIX)
|
||||
srand((*((long *)kshname)) ^ ((long)time(NULL) * kshpid * ppid));
|
||||
#endif
|
||||
setint(global("PPID"), (long) ppid);
|
||||
/* setstr can't fail here */
|
||||
if (!Flag(FSH))
|
||||
|
10
var.c
10
var.c
@ -1,4 +1,4 @@
|
||||
/** $MirOS: src/bin/mksh/var.c,v 1.1 2005/05/23 03:06:10 tg Exp $ */
|
||||
/** $MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 tg Exp $ */
|
||||
/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
|
||||
|
||||
#include "sh.h"
|
||||
@ -6,7 +6,7 @@
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.1 2005/05/23 03:06:10 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -855,7 +855,11 @@ makenv(void)
|
||||
* Someone has set the srand() value, therefore from now on
|
||||
* we return values from rand() instead of arc4random()
|
||||
*/
|
||||
#if !defined(__gnu_linux__) && !defined(__INTERIX)
|
||||
int use_rand = 0;
|
||||
#else
|
||||
int use_rand = 1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Called after a fork in parent to bump the random number generator.
|
||||
@ -915,8 +919,10 @@ getspec(struct tbl *vp)
|
||||
vp->flag &= ~SPECIAL;
|
||||
if (use_rand)
|
||||
setint(vp, (long) (rand() & 0x7fff));
|
||||
#if !defined(__gnu_linux__) && !defined(__INTERIX)
|
||||
else
|
||||
setint(vp, (long) (arc4random() & 0x7fff));
|
||||
#endif
|
||||
vp->flag |= SPECIAL;
|
||||
break;
|
||||
case V_HISTSIZE:
|
||||
|
Loading…
x
Reference in New Issue
Block a user