Skip to content

Commit 63e7cc7

Browse files
joyeecheungtargos
authored andcommitted
src: forbid access to CLI options before bootstrapping is done
PR-URL: #26476 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent e6c1ad5 commit 63e7cc7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/internal/async_hooks.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const {
55
ERR_INVALID_ASYNC_ID
66
} = require('internal/errors').codes;
77

8-
const { getOptionValue } = require('internal/options');
9-
const shouldAbortOnUncaughtException =
10-
getOptionValue('--abort-on-uncaught-exception');
11-
128
const async_wrap = internalBinding('async_wrap');
139
/* async_hook_fields is a Uint32Array wrapping the uint32_t array of
1410
* Environment::AsyncHooks::fields_[]. Each index tracks the number of active
@@ -102,7 +98,9 @@ function fatalError(e) {
10298
Error.captureStackTrace(o, fatalError);
10399
process._rawDebug(o.stack);
104100
}
105-
if (shouldAbortOnUncaughtException) {
101+
102+
const { getOptionValue } = require('internal/options');
103+
if (getOptionValue('--abort-on-uncaught-exception')) {
106104
process.abort();
107105
}
108106
process.exit(1);

src/node_options.cc

+6
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ HostPort SplitHostPort(const std::string& arg,
548548
void GetOptions(const FunctionCallbackInfo<Value>& args) {
549549
Mutex::ScopedLock lock(per_process::cli_options_mutex);
550550
Environment* env = Environment::GetCurrent(args);
551+
if (!env->has_run_bootstrapping_code()) {
552+
// No code because this is an assertion.
553+
return env->ThrowError(
554+
"Should not query options before bootstrapping is done");
555+
}
556+
551557
Isolate* isolate = env->isolate();
552558
Local<Context> context = env->context();
553559

0 commit comments

Comments
 (0)