Skip to content

Commit

Permalink
src: use option parser for expose_internals
Browse files Browse the repository at this point in the history
bootstrap_node.js was directly parsing process.execArgv to see if
internals should be exposed, even though the argv was already parsed by
node. This is unusual and unnecessary, change it to set the option value
from the parser onto the process object, as is done for the other CLI
options.
  • Loading branch information
sam-github committed Apr 10, 2017
1 parent 937a3d1 commit 8b07404
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,10 @@
return NativeModule._source.hasOwnProperty(id);
};

const EXPOSE_INTERNALS = process.execArgv.some(function(arg) {
return arg.match(/^--expose[-_]internals$/);
});
const EXPOSE_INTERNALS = process._exposeInternals;

if (EXPOSE_INTERNALS) {
delete process._exposeInternals;
NativeModule.nonInternalExists = NativeModule.exists;

NativeModule.isInternal = function(id) {
Expand Down
10 changes: 9 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ static bool trace_sync_io = false;
static bool track_heap_objects = false;
static const char* eval_string = nullptr;
static std::vector<std::string> preload_modules;
static bool expose_internals = false;
static const int v8_default_thread_pool_size = 4;
static int v8_thread_pool_size = v8_default_thread_pool_size;
static bool prof_process = false;
Expand Down Expand Up @@ -3333,6 +3334,13 @@ void SetupProcessObject(Environment* env,
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
}

// --expose_internals, --expose-internals
// Note that this is not exposed as a process property, it is deleted when
// node's javascript bootstrap code runs.
if (expose_internals) {
READONLY_PROPERTY(process, "_exposeInternals", True(env->isolate()));
}

// --security-revert flags
#define V(code, _, __) \
do { \
Expand Down Expand Up @@ -3786,7 +3794,7 @@ static void ParseArgs(int* argc,
#endif
} else if (strcmp(arg, "--expose-internals") == 0 ||
strcmp(arg, "--expose_internals") == 0) {
// consumed in js
expose_internals = true;
} else if (strcmp(arg, "--") == 0) {
index += 1;
break;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-internal-modules-expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ require('../common');
const assert = require('assert');

assert.strictEqual(typeof require('internal/freelist').FreeList, 'function');
assert(!('_exposeInternals' in process), 'no process property is leaked');

0 comments on commit 8b07404

Please sign in to comment.