Skip to content

Commit

Permalink
src: forbid access to CLI options before bootstrapping is done
Browse files Browse the repository at this point in the history
PR-URL: nodejs#26476
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
joyeecheung committed Mar 9, 2019
1 parent 4e9dc31 commit d57d099
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,7 +108,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);
Expand Down
6 changes: 6 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ HostPort SplitHostPort(const std::string& arg,
void GetOptions(const FunctionCallbackInfo<Value>& 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> context = env->context();

Expand Down

0 comments on commit d57d099

Please sign in to comment.