Skip to content

Commit

Permalink
Don't case arc4random: oconfigure provides.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsdz committed Sep 15, 2024
1 parent 4afd4c5 commit 18cab7e
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 84 deletions.
7 changes: 1 addition & 6 deletions fcgi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2015--2016, 2018 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -169,11 +168,7 @@ kfcgi_control(int work, int ctrl,

/* This doesn't need to be crypto quality. */

#if HAVE_ARC4RANDOM
cookie = arc4random();
#else
cookie = random();
#endif

/* Write a header cookie to the work. */

Expand Down
7 changes: 1 addition & 6 deletions kfcgi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2015--2016 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -681,11 +680,7 @@ varpool(size_t wsz, size_t maxwsz, time_t waittime,

assert(i < wsz);
ws[i].fd = afd;
#if HAVE_ARC4RANDOM
ws[i].cookie = arc4random();
#else
ws[i].cookie = random();
#endif
dbg("worker-%u: acquire %d "
"(pollers %zu/%zu: workers %zu/%zu)",
ws[i].pid, afd, pfdsz, pfdmaxsz, wsz, maxwsz);
Expand Down
11 changes: 1 addition & 10 deletions regress/test-date2epoch.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -53,11 +52,7 @@ main(int argc, char *argv[])
*/

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (time_t)arc4random();
#else
v = (time_t)random();
#endif
if (!KHTTP_EPOCH2TM(v, &test))
errx(1, "KHTTP_EPOCH2TM");

Expand All @@ -84,11 +79,7 @@ main(int argc, char *argv[])
}

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (time_t)arc4random() * -1;
#else
v = (time_t)random() * -1;
#endif
if (!KHTTP_EPOCH2TM(v, &test))
errx(1, "KHTTP_EPOCH2TM");

Expand Down
15 changes: 1 addition & 14 deletions regress/test-datetime-deprecated.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2016 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -41,19 +40,7 @@ main(int argc, char *argv[])
char inbuf[64], testbuf[64];

for (i = 0; i < 100000; i++) {
/*
* arc4random_uniform is of course fine on BSD systems,
* but isn't implemented properly on all systems, e.g.,
* Alpine Linux, so we don't pull in <bsd/stdlib.h> and
* this might cause compile problems.
* We would do more values, but Linux sometimes has
* 32-bit time.
*/
#if HAVE_ARC4RANDOM
v = arc4random_uniform(50 * 365 * 24 * 60 * 60);
#else
v = random() % (50 * 365 * 24 * 60 * 60);
#endif
tm = gmtime(&v);
strftime(inbuf, sizeof(inbuf), "%a, %d %b %Y %T GMT", tm);
kutil_epoch2str(v, testbuf, sizeof(testbuf));
Expand Down
11 changes: 1 addition & 10 deletions regress/test-datetime2epoch.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -46,11 +45,7 @@ main(int argc, char *argv[])
*/

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = arc4random();
#else
v = random();
#endif
if (!KHTTP_EPOCH2TM(v, &test))
errx(1, "KHTTP_EPOCH2TM");
if (!khttp_datetime2epoch(&res,
Expand All @@ -67,11 +62,7 @@ main(int argc, char *argv[])
}

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (int64_t)arc4random() * -1;
#else
v = (int64_t)random() * -1;
#endif
if (!KHTTP_EPOCH2TM(v, &test))
errx(1, "KHTTP_EPOCH2TM");
if (!khttp_datetime2epoch(&res,
Expand Down
10 changes: 1 addition & 9 deletions regress/test-epoch2datetime.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -95,14 +94,7 @@ main(int argc, char *argv[])
/* Test across random values. */

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
arc4random_buf(&v, sizeof(int64_t));
#else
vv = (int64_t)random() * (int64_t)random();
memcpy(&v, &vv, sizeof(uint32_t));
vv = (int64_t)random() * (int64_t)random();
memcpy((void *)&v + sizeof(uint32_t), &vv, sizeof(uint32_t));
#endif
khttp_epoch2datetime(v,
&tm_sec,
&tm_min,
Expand Down
7 changes: 1 addition & 6 deletions regress/test-epoch2str.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2016, 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -47,11 +46,7 @@ main(int argc, char *argv[])
*/

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (int32_t)arc4random();
#else
v = (int32_t)(random() + random());
#endif
tm = gmtime(&v);
strftime(buf, sizeof(buf), "%a, %d %b %Y %T GMT", tm);
khttp_epoch2str(v, testbuf, sizeof(testbuf));
Expand Down
7 changes: 1 addition & 6 deletions regress/test-epoch2tm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -47,11 +46,7 @@ main(int argc, char *argv[])
*/

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (int32_t)arc4random();
#else
v = (int32_t)(random() + random());
#endif
if ((tm = gmtime(&v)) == NULL)
err(1, "gmtime");
have = *tm;
Expand Down
7 changes: 1 addition & 6 deletions regress/test-epoch2tms.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -43,11 +42,7 @@ main(int argc, char *argv[])
int c;

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (time_t)arc4random();
#else
v = (time_t)random();
#endif
if ((tm = gmtime(&v)) == NULL) {
warnx("gmtime: %" PRId64, (int64_t)v);
continue;
Expand Down
7 changes: 1 addition & 6 deletions regress/test-epoch2ustr.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2016, 2020 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -47,11 +46,7 @@ main(int argc, char *argv[])
*/

for (i = 0; i < 100000; i++) {
#if HAVE_ARC4RANDOM
v = (int32_t)arc4random();
#else
v = (int32_t)(random() + random());
#endif
tm = gmtime(&v);
strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tm);
khttp_epoch2ustr(v, testbuf, sizeof(testbuf));
Expand Down
6 changes: 1 addition & 5 deletions regress/test-gzip-bigfile.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* $Id$ */
/*
* Copyright (c) 2015 Kristaps Dzonsons <[email protected]>
* Copyright (c) Kristaps Dzonsons <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -30,9 +29,6 @@
#if HAVE_ZLIB

#define BUFSZ (1024 * 1024)
#ifdef __linux__
#define arc4random random
#endif

static size_t
doign(void *ptr, size_t sz, size_t nm, void *arg)
Expand Down

0 comments on commit 18cab7e

Please sign in to comment.