Skip to content

Commit

Permalink
tests: fopen /dev/urandom in binary mode
Browse files Browse the repository at this point in the history
This makes a difference with mingw builds on Wine, where the subsequent
fread() may abort early in the default text mode.

The Microsoft C docs say:
"In text mode, CTRL+Z is interpreted as an EOF character on input."
  • Loading branch information
real-or-random authored and sipa committed May 2, 2021
1 parent 4dc37bf commit ed5a199
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/testrand_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void secp256k1_testrand_init(const char* hexseed) {
pos++;
}
} else {
FILE *frand = fopen("/dev/urandom", "r");
FILE *frand = fopen("/dev/urandom", "rb");
if ((frand == NULL) || fread(&seed16, 1, sizeof(seed16), frand) != sizeof(seed16)) {
uint64_t t = time(NULL) * (uint64_t)1337;
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
Expand Down

0 comments on commit ed5a199

Please sign in to comment.