From c5751ce72cde2785ae778dd4a3a39f712cb7f808 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Mon, 23 Sep 2013 14:11:32 +0000 Subject: [PATCH] Let SetEntropySource() fail if called after V8::Initialize(). BUG=v8:2905 R=dslomov@chromium.org Review URL: https://codereview.chromium.org/24357002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16889 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 3 +++ src/api.cc | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/include/v8.h b/include/v8.h index 4206105..2811082 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4540,6 +4540,9 @@ class V8_EXPORT V8 { /** * Allows the host application to provide a callback which can be used * as a source of entropy for random number generators. + * + * \note Setting an entropy source can only be done very early prior to + * calling Initialize(). */ static void SetEntropySource(EntropySource source); diff --git a/src/api.cc b/src/api.cc index 9756874..e3cde52 100644 --- a/src/api.cc +++ b/src/api.cc @@ -5175,6 +5175,13 @@ bool v8::V8::Initialize() { void v8::V8::SetEntropySource(EntropySource entropy_source) { + // The entropy source must be set before the library is initialized, + // as otherwise not all random number generators will pick up the + // entropy source and will fall back to weak entropy instead. + i::Isolate* isolate = i::Isolate::UncheckedCurrent(); + ApiCheck(isolate != NULL && isolate->IsInitialized(), + "v8::V8::SetEntropySource", + "Cannot set entropy source once V8 is initialized."); i::RandomNumberGenerator::SetEntropySource(entropy_source); } -- 2.7.4