From 63e7cc7694f07697b9a8540dea85a68f390bfdc3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 6 Mar 2019 15:38:59 +0100 Subject: [PATCH] src: forbid access to CLI options before bootstrapping is done PR-URL: https://github.com/nodejs/node/pull/26476 Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater Reviewed-By: Richard Lau --- lib/internal/async_hooks.js | 8 +++----- src/node_options.cc | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index eeec0e6f82f36c..53c8d08a7d9af9 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -5,10 +5,6 @@ const { ERR_INVALID_ASYNC_ID } = require('internal/errors').codes; -const { getOptionValue } = require('internal/options'); -const shouldAbortOnUncaughtException = - getOptionValue('--abort-on-uncaught-exception'); - const async_wrap = internalBinding('async_wrap'); /* async_hook_fields is a Uint32Array wrapping the uint32_t array of * Environment::AsyncHooks::fields_[]. Each index tracks the number of active @@ -102,7 +98,9 @@ function fatalError(e) { Error.captureStackTrace(o, fatalError); process._rawDebug(o.stack); } - if (shouldAbortOnUncaughtException) { + + const { getOptionValue } = require('internal/options'); + if (getOptionValue('--abort-on-uncaught-exception')) { process.abort(); } process.exit(1); diff --git a/src/node_options.cc b/src/node_options.cc index f384957db5bef3..fb9b6c59788a73 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -548,6 +548,12 @@ HostPort SplitHostPort(const std::string& arg, void GetOptions(const FunctionCallbackInfo& args) { Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(args); + if (!env->has_run_bootstrapping_code()) { + // No code because this is an assertion. + return env->ThrowError( + "Should not query options before bootstrapping is done"); + } + Isolate* isolate = env->isolate(); Local context = env->context();