From 6c2ba8d2215b27eeeb16e8b41f9b8497f384f593 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 15 Aug 2019 14:39:26 +0200 Subject: [PATCH] tools: make code cache and snapshot deterministic Use a fixed random seed to ensure that the generated sources are identical across runs. The final node binary still reseeds itself on start-up so there should be no security implications caused by predictable random numbers (e.g., `Math.random()`, ASLR, the hash seed, etc.) Fixes: https://github.com/nodejs/node/issues/29108 --- tools/code_cache/mkcodecache.cc | 2 ++ tools/snapshot/node_mksnapshot.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/code_cache/mkcodecache.cc b/tools/code_cache/mkcodecache.cc index defa1462ce45ec..bc45d46a43b6cd 100644 --- a/tools/code_cache/mkcodecache.cc +++ b/tools/code_cache/mkcodecache.cc @@ -26,6 +26,8 @@ int wmain(int argc, wchar_t* argv[]) { int main(int argc, char* argv[]) { #endif // _WIN32 + v8::V8::SetFlagsFromString("--random_seed=42"); + if (argc < 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1; diff --git a/tools/snapshot/node_mksnapshot.cc b/tools/snapshot/node_mksnapshot.cc index f52cccb705f53a..29f9e1cbcbb096 100644 --- a/tools/snapshot/node_mksnapshot.cc +++ b/tools/snapshot/node_mksnapshot.cc @@ -19,6 +19,8 @@ int wmain(int argc, wchar_t* argv[]) { int main(int argc, char* argv[]) { #endif // _WIN32 + v8::V8::SetFlagsFromString("--random_seed=42"); + if (argc < 2) { std::cerr << "Usage: " << argv[0] << " \n"; return 1;