diff options
author | Francis Dupont <fdupont@isc.org> | 2022-01-05 20:21:43 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2022-01-12 08:53:55 -0500 |
commit | 46de3dfd990ab53e953aacda42d8085cc4c09322 (patch) | |
tree | aa0f8671f65abe782bfe5fed01269bd304a56211 | |
parent | eece3e17eb3b4a30d56f28cdf57e6fe63121e121 (diff) | |
download | isc-dhcp-46de3dfd990ab53e953aacda42d8085cc4c09322.tar.gz |
Mixed with srandomdev() BSD code
-rw-r--r-- | client/dhclient.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/client/dhclient.c b/client/dhclient.c index e445a52d..a0ff656b 100644 --- a/client/dhclient.c +++ b/client/dhclient.c @@ -3,7 +3,7 @@ DHCP Client. */ /* - * Copyright (c) 2004-2020 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2004-2022 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-2003 by Internet Software Consortium * * This Source Code Form is subject to the terms of the Mozilla Public @@ -829,21 +829,36 @@ main(int argc, char **argv) { ? DISCOVER_REQUESTED : DISCOVER_RUNNING); - /* Make up a seed for the random number generator from current - time plus the sum of the last four bytes of each - interface's hardware address interpreted as an integer. - Not much entropy, but we're booting, so we're not likely to - find anything better. */ + /* PLEASE PREFER the random device: not all systems use random + * process identifiers so the alternative can be predictable. */ seed = 0; - for (ip = interfaces; ip; ip = ip->next) { - int junk; - memcpy(&junk, - &ip->hw_address.hbuf[ip->hw_address.hlen - - sizeof seed], sizeof seed); - seed += junk; + size_t nrnd = 0; +#ifdef ISC_PATH_RANDOMDEV + FILE *frnd = fopen(ISC_PATH_RANDOMDEV, "r"); + if (frnd) { + nrnd = fread(&seed, sizeof(seed), 1, frnd); + fclose(frnd); } - srandom(seed + cur_time + (unsigned)getpid()); +#endif + /* Please leave the compiler to emit a warning about a constant + * condition in the if test. */ + if (!nrnd) { + /* Make up a seed for the random number generator from current + time plus the sum of the last four bytes of each + interface's hardware address interpreted as an integer. + Not much entropy, but we're booting, so we're not likely to + find anything better. */ + for (ip = interfaces; ip; ip = ip->next) { + int junk; + memcpy(&junk, + &ip->hw_address.hbuf[ip->hw_address.hlen - + sizeof seed], sizeof seed); + seed += junk; + } + seed += cur_time + (unsigned)getpid(); + } + srandom(seed); /* * Establish a default DUID. We always do so for v6 and |