• avoid calling arc4random_pushb for inheritance and other redundant items;

call it only if $RANDOM is indeed set (although pool extension would be a
  possibility we do have arc4random_atexit which does it nicely too)
• avoid calling setspec for int→str conversion just before execve()
This commit is contained in:
tg 2009-09-27 10:31:06 +00:00
parent 7b7b75b026
commit c8955138ec
2 changed files with 10 additions and 7 deletions

4
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h> #include <locale.h>
#endif #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; extern char **environ;
@ -269,8 +269,8 @@ main(int argc, const char *argv[])
setint(global("OPTIND"), 1); setint(global("OPTIND"), 1);
vp = global("RANDOM"); vp = global("RANDOM");
#if HAVE_ARC4RANDOM #if HAVE_ARC4RANDOM
/* avoid calling setspec */
Flag(FARC4RANDOM) = 1; Flag(FARC4RANDOM) = 1;
/* avoid calling setspec */
vp->flag |= ISSET | INT_U; vp->flag |= ISSET | INT_U;
#else #else
vp->flag |= INT_U; vp->flag |= INT_U;

13
var.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #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 * Variables
@ -962,7 +962,7 @@ makenv(void)
/* integer to string */ /* integer to string */
char *val; char *val;
val = str_val(vp); val = str_val(vp);
vp->flag &= ~(INTEGER|RDONLY); vp->flag &= ~(INTEGER|RDONLY|SPECIAL);
/* setstr can't fail here */ /* setstr can't fail here */
setstr(vp, val, KSH_RETURN_ERROR); setstr(vp, val, KSH_RETURN_ERROR);
} }
@ -983,10 +983,13 @@ static void
rnd_set(unsigned long newval) rnd_set(unsigned long newval)
{ {
#if HAVE_ARC4RANDOM_PUSHB #if HAVE_ARC4RANDOM_PUSHB
arc4random_pushb(&newval, sizeof(newval)); if (Flag(FARC4RANDOM))
#else /* initialisation, environment import, etc. already done */
arc4random_addrandom((void *)&newval, sizeof(newval)); arc4random_pushb(&newval, sizeof(newval));
else
/* during start-up phase or somesuch */
#endif #endif
arc4random_addrandom((void *)&newval, sizeof(newval));
} }
#else #else
static int static int