Due to the removal of pthread_once, we manually create the seed for
chunk_hash(). With the new testable functions interface, this won't work for
the hashtable initiated using __attribute__((constructor)). Enforce seeding
before creating that hashtable.
{
private_library_t *this;
printf_hook_t *pfh;
- static bool seeded = FALSE;
if (lib)
{ /* already initialized, increase refcount */
return !this->integrity_failed;
}
- if (!seeded)
- {
- /* we do this just once to allow hash table lifetimes longer than
- * one init/deinit cycle. */
- seeded = TRUE;
- chunk_hash_seed();
- }
+ chunk_hash_seed();
INIT(this,
.public = {
{
if (!testable_functions)
{
+ /* as this is executed before chunk_hash() seed initialization used
+ * by hashtables, we enforce seeding it here. */
+ chunk_hash_seed();
testable_functions = hashtable_create(hashtable_hash_str,
hashtable_equals_str, 8);
}
*/
void chunk_hash_seed()
{
+ static bool seeded = FALSE;
ssize_t len;
size_t done = 0;
int fd;
+ if (seeded)
+ {
+ /* just once to have the same seed during the whole process lifetimes */
+ return;
+ }
+
fd = open("/dev/urandom", O_RDONLY);
if (fd >= 0)
{
key[done] = (u_char)random();
}
}
+ seeded = TRUE;
}
/**
* Seed initial key for chunk_hash().
*
* This call should get invoked once during startup. This is usually done
- * by calling library_init().
+ * by calling library_init(). Calling it multiple times is safe, it gets
+ * executed just once.
*/
void chunk_hash_seed();