Squashed commit of the following:
commit
e78a4bc6b5663229ec919a626ad8c942c0d3734e
Author: Oleksii Khomiakovskyi <okhomiak@cisco.com>
Date: Mon Sep 28 11:54:51 2020 +0300
utils: add a generic function to get random seeds
If std::random_device fails with an exception,
the system clock is used as an alternative source.
#include "protocols/ipv4_options.h"
#include "protocols/tcp.h"
#include "sfip/sf_ipvar.h"
+#include "utils/util.h"
#include "checksum.h"
static void ipv4_codec_tinit()
{
- std::random_device rd; // for a good seed
- auto id = rd();
-
- if (SnortConfig::static_hash())
- id = 1;
-
- thread_rand = new std::mt19937(id);
+ thread_rand = new std::mt19937(SnortConfig::static_hash() ? 1 : get_random_seed());
}
static void ipv4_codec_tterm()
#include <random>
#include "main/snort_config.h"
+#include "utils/util.h"
using namespace snort;
RandomFlushBucket::RandomFlushBucket()
{
- std::random_device random_dev;
- std::default_random_engine generator(random_dev());
+ std::default_random_engine generator(get_random_seed());
std::uniform_int_distribution<int> distribution(128, 255);
for ( int i = 0; i < NUM_FLUSH_POINTS; i++ )
#include <daq.h>
}
+#include <chrono>
#include <fstream>
+#include <random>
#include "log/messages.h"
#include "main/build.h"
return true;
}
+unsigned int get_random_seed()
+{
+ unsigned int seed;
+
+ try {
+ seed = std::random_device{}();
+ } catch ( const std::exception& ) {
+ seed = std::chrono::system_clock::now().time_since_epoch().count();
+ }
+
+ return seed;
+}
+
#if defined(NOCOREFILE)
void SetNoCores()
{
void InitGroups(int, int);
bool EnterChroot(std::string& root_dir, std::string& log_dir);
void InitProtoNames();
+unsigned int get_random_seed();
#if defined(NOCOREFILE)
void SetNoCores();