Set ADDR_NO_RANDOMIZE on linux for determinism

This commit is contained in:
2022-01-28 12:48:59 -05:00
parent 301fe24617
commit 9d7bf8b0f9
4 changed files with 17 additions and 3 deletions

View File

@@ -435,6 +435,7 @@ public:
} }
void drive(DrivenEngine *de, int argc, char *argv[]) { void drive(DrivenEngine *de, int argc, char *argv[]) {
disable_randomization(argc, argv);
socket_init(); socket_init();
SSL_load_error_strings(); SSL_load_error_strings();
ERR_load_crypto_strings(); ERR_load_crypto_strings();

View File

@@ -19,6 +19,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/personality.h>
#include <netdb.h> #include <netdb.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
@@ -232,6 +233,16 @@ static void fill_stdio_pollfd(PollVector &pollvec, int &mstimeout, bool read_con
stdiopoll.events = POLLIN; stdiopoll.events = POLLIN;
} }
static void disable_randomization(int argc, char *argv[]) {
const int old_personality = personality(ADDR_NO_RANDOMIZE);
if (!(old_personality & ADDR_NO_RANDOMIZE)) {
const int new_personality = personality(ADDR_NO_RANDOMIZE);
if (new_personality & ADDR_NO_RANDOMIZE) {
execv(argv[0], argv);
}
}
}
class MonoClock { class MonoClock {
private: private:
struct timespec base_; struct timespec base_;

View File

@@ -252,6 +252,10 @@ static void fill_stdio_pollfd(PollVector &pollvec, int &mstimeout, bool read_con
if (mstimeout > 100) mstimeout = 100; if (mstimeout > 100) mstimeout = 100;
} }
static void disable_randomization(int argc, char *argv[]) {
// Do nothing.
}
class MonoClock { class MonoClock {
public: public:
double freq_; double freq_;

View File

@@ -45,8 +45,6 @@ int main(int argc, char **argv)
} }
} }
if (engine == nullptr) usage(); if (engine == nullptr) usage();
// Remove one argument from the argument vector, driver_drive(engine.get(), argc, argv);
// so that it looks like a normal argument vector.
driver_drive(engine.get(), argc - 1, argv + 1);
} }