summaryrefslogtreecommitdiffstats
path: root/usr.sbin/httpd/src
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2004-05-16 18:42:09 +0000
committerotto <otto@openbsd.org>2004-05-16 18:42:09 +0000
commit872084db3ccad9f21c426e1ac5d61e1e82097912 (patch)
tree3f6c9215262b2f21457e880644ada4b0bc057de5 /usr.sbin/httpd/src
parentUse arc4random(3) instead of rand(3) to compute random numbers. (diff)
downloadwireguard-openbsd-872084db3ccad9f21c426e1ac5d61e1e82097912.tar.xz
wireguard-openbsd-872084db3ccad9f21c426e1ac5d61e1e82097912.zip
Use arc4random(3) to compute random numbers, instead of using rand()
to produce a double, snprintf()ing that into a buffer and then converting the string to an int with atoi(). ok millert@ henning@
Diffstat (limited to 'usr.sbin/httpd/src')
-rw-r--r--usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c b/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c
index 86cbf6a0653..5adad9c36ff 100644
--- a/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c
+++ b/usr.sbin/httpd/src/modules/ssl/ssl_engine_rand.c
@@ -71,7 +71,7 @@
** _________________________________________________________________
*/
-static int ssl_rand_choosenum(int, int);
+static int ssl_rand_choosenum(int);
static int ssl_rand_feedfp(pool *, FILE *, int);
int ssl_rand_seed(server_rec *s, pool *p, ssl_rsctx_t nCtx, char *prefix)
@@ -155,7 +155,7 @@ int ssl_rand_seed(server_rec *s, pool *p, ssl_rsctx_t nCtx, char *prefix)
/*
* seed in some current state of the run-time stack (128 bytes)
*/
- n = ssl_rand_choosenum(0, sizeof(stackdata)-128-1);
+ n = ssl_rand_choosenum(sizeof(stackdata)-128-1);
RAND_seed(stackdata+n, 128);
nDone += 128;
@@ -165,7 +165,7 @@ int ssl_rand_seed(server_rec *s, pool *p, ssl_rsctx_t nCtx, char *prefix)
if (ap_scoreboard_image != NULL && SCOREBOARD_SIZE > 16) {
if ((m = ((SCOREBOARD_SIZE / 2) - 1)) > 1024)
m = 1024;
- n = ssl_rand_choosenum(0, m);
+ n = ssl_rand_choosenum(m);
RAND_seed(((unsigned char *)ap_scoreboard_image)+n, m);
nDone += m;
}
@@ -210,17 +210,9 @@ static int ssl_rand_feedfp(pool *p, FILE *fp, int nReq)
return nDone;
}
-static int ssl_rand_choosenum(int l, int h)
+/* Generate a random number in the range 1-h */
+static int ssl_rand_choosenum(int h)
{
- int i;
- char buf[50];
-
- srand((unsigned int)time(NULL));
- ap_snprintf(buf, sizeof(buf), "%.0f",
- (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
- i = atoi(buf)+1;
- if (i < l) i = l;
- if (i > h) i = h;
- return i;
+ return (int)(arc4random() / ((double)0xffffffffU + 1) * h + 1);
}