Skip to content

Commit 20c5869

Browse files
committed
Merge bitcoin#516: improvements to random seed in src/tests.c
be40c4d Fixup for C90 mixed declarations. (Gregory Maxwell) 8b3841c fix bug in fread() failure check (Don Viszneki) cddef0c tests: add warning message when /dev/urandom fails (Don Viszneki) Pull request description: I've made two small changes to `src/tests.c` circa random seed generation. Added a warning when `/dev/urandom` fails, mostly to defend against the case that someone should use the code verbatim, but also to enhance its illustrative power. Also I fixed a bug with how the return value of `fread()` was being evaluated. In fact, `/dev/urandom` was never being applied before as the check on the return value of `fread()` always failed! Tree-SHA512: 239dbe8316220c2f0e5b370bf9a18f78196e96cc4a7edea58cf2521b2c9cbc8da065be96aa859f90324d57e388d30f7670ce6bc1cca52e5162e5ca66b1a55b34
2 parents 870a977 + be40c4d commit 20c5869

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/tests.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4994,8 +4994,9 @@ int main(int argc, char **argv) {
49944994
}
49954995
} else {
49964996
FILE *frand = fopen("/dev/urandom", "r");
4997-
if ((frand == NULL) || fread(&seed16, sizeof(seed16), 1, frand) != sizeof(seed16)) {
4997+
if ((frand == NULL) || fread(&seed16, 1, sizeof(seed16), frand) != sizeof(seed16)) {
49984998
uint64_t t = time(NULL) * (uint64_t)1337;
4999+
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
49995000
seed16[0] ^= t;
50005001
seed16[1] ^= t >> 8;
50015002
seed16[2] ^= t >> 16;

0 commit comments

Comments
 (0)