2022-08-22 Paul Eggert <eggert@cs.ucla.edu>
+ tempname: don't lose entropy in seed
+ * lib/tempname.c (random_bits): Don't lose entropy in S
+ in the rare case where where the template has more than 10 Xs.
+ From a suggestion by Bruno Haible in:
+ https://bugs.gnu.org/57129#149
+
tempname: fix multithreading, ASLR leak etc.
Fix problems with tempname and multithreading, entropy loss,
and missing clock data (this last on non-GNU platforms).
Do not try to use a static var as that has issues if multithreaded.
Instead, simply generate new random bits.
Worry about bias only with high-quality random bits.
+
* modules/tempname (Depends-on): Do not depend on stdalign.
tempname: merge 64-bit time_t fix from glibc
Of course we are in a state of sin here. */
- random_value v = 0;
+ random_value v = s;
#if _LIBC || (defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME)
struct __timespec64 tv;
/* A random variable. */
random_value v = 0;
- /* How many random base-62 digits can currently be extracted from V. */
+ /* A value derived from the random variable, and how many random
+ base-62 digits can currently be extracted from VDIGBUF. */
+ random_value vdigbuf;
int vdigits = 0;
/* Least biased value for V. If V is less than this, V can generate
while (random_bits (&v, v) && biased_min <= v)
continue;
+ vdigbuf = v;
vdigits = BASE_62_DIGITS;
}
- XXXXXX[i] = letters[v % 62];
- v /= 62;
+ XXXXXX[i] = letters[vdigbuf % 62];
+ vdigbuf /= 62;
vdigits--;
}