1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(ipc): allow IPC under windows by not using std::random_device with mingw

https://en.cppreference.com/w/cpp/numeric/random/random_device
"A notable implementation where std::random_device is deterministic is old
versions of MinGW (bug 338, fixed since GCC 9.2)."

Although time is less random off Windows, we don't need a strongly random
number for this, and using time avoids having to use platform specific code.

Fix #2917
This commit is contained in:
Anthony Bilinski 2020-04-30 18:37:30 -07:00
parent 82547263f8
commit 6105af8279
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -22,6 +22,7 @@
#include <QDebug>
#include <QThread>
#include <chrono>
#include <ctime>
#include <random>
#include <stdlib.h>
@ -85,9 +86,11 @@ IPC::IPC(uint32_t profileId)
// If the owner exits normally, it can set the timestamp to 0 first to immediately give
// ownership
std::default_random_engine randEngine((std::random_device())());
// use the clock rather than std::random_device because std::random_device may return constant values, and does
// under mingw on Windows. We don't actually need cryptographic guarantees, so using the clock in all cases.
static std::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
std::uniform_int_distribution<uint64_t> distribution;
globalId = distribution(randEngine);
globalId = distribution(rng);
qDebug() << "Our global IPC ID is " << globalId;
if (globalMemory.create(sizeof(IPCMemory))) {
if (globalMemory.lock()) {