From 820f4b1de1df1fe75be68ede5d1f3ef09520294d Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 23 May 2005 14:22:03 +0000 Subject: [PATCH] always use rand(3) on platforms without arc4random(3) and seed it --- main.c | 7 +++++-- var.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 1a9a453..43f3e45 100644 --- a/main.c +++ b/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 #include -__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)) diff --git a/var.c b/var.c index 518f5ce..f013e45 100644 --- a/var.c +++ b/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 #include -__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: