From c8955138ecd41557cdb87819158de1abf015b616 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 27 Sep 2009 10:31:06 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20avoid=20calling=20arc4random=5Fpush?= =?UTF-8?q?b=20for=20inheritance=20and=20other=20redundant=20items;=20=20?= =?UTF-8?q?=20call=20it=20only=20if=20$RANDOM=20is=20indeed=20set=20(altho?= =?UTF-8?q?ugh=20pool=20extension=20would=20be=20a=20=20=20possibility=20w?= =?UTF-8?q?e=20do=20have=20arc4random=5Fatexit=20which=20does=20it=20nicel?= =?UTF-8?q?y=20too)=20=E2=80=A2=20avoid=20calling=20setspec=20for=20int?= =?UTF-8?q?=E2=86=92str=20conversion=20just=20before=20execve()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 4 ++-- var.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 001a215..28773c0 100644 --- a/main.c +++ b/main.c @@ -33,7 +33,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.149 2009/09/26 03:40:00 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.150 2009/09/27 10:31:06 tg Exp $"); extern char **environ; @@ -269,8 +269,8 @@ main(int argc, const char *argv[]) setint(global("OPTIND"), 1); vp = global("RANDOM"); #if HAVE_ARC4RANDOM - /* avoid calling setspec */ Flag(FARC4RANDOM) = 1; + /* avoid calling setspec */ vp->flag |= ISSET | INT_U; #else vp->flag |= INT_U; diff --git a/var.c b/var.c index 71f7c0d..8bd4075 100644 --- a/var.c +++ b/var.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.93 2009/09/26 04:01:34 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.94 2009/09/27 10:31:06 tg Exp $"); /* * Variables @@ -962,7 +962,7 @@ makenv(void) /* integer to string */ char *val; val = str_val(vp); - vp->flag &= ~(INTEGER|RDONLY); + vp->flag &= ~(INTEGER|RDONLY|SPECIAL); /* setstr can't fail here */ setstr(vp, val, KSH_RETURN_ERROR); } @@ -983,10 +983,13 @@ static void rnd_set(unsigned long newval) { #if HAVE_ARC4RANDOM_PUSHB - arc4random_pushb(&newval, sizeof(newval)); -#else - arc4random_addrandom((void *)&newval, sizeof(newval)); + if (Flag(FARC4RANDOM)) + /* initialisation, environment import, etc. already done */ + arc4random_pushb(&newval, sizeof(newval)); + else + /* during start-up phase or somesuch */ #endif + arc4random_addrandom((void *)&newval, sizeof(newval)); } #else static int