Skip to content

Commit

Permalink
process: delay creation of process.env after bootstrap/node.js
Browse files Browse the repository at this point in the history
Make sure that no code is allowed to access process.env during
the execution of bootstrap/node.js.

PR-URL: #26515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Mar 27, 2019
1 parent cc4a25a commit 57d302b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
MaybeLocal<Value> result = ExecuteBootstrapper(
env, "internal/bootstrap/node", &node_params, &node_args);

Local<Object> env_var_proxy;
if (!CreateEnvVarProxy(context, isolate, env->as_callback_data())
.ToLocal(&env_var_proxy) ||
process
->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
env_var_proxy)
.IsNothing())
return MaybeLocal<Value>();

env->set_has_run_bootstrapping_code(true);

return scope.EscapeMaybe(result);
Expand Down
12 changes: 0 additions & 12 deletions src/node_process_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ MaybeLocal<Object> CreateProcessObject(
ToV8Value(env->context(), exec_args)
.ToLocalChecked()).FromJust();

Local<Object> env_var_proxy;
if (!CreateEnvVarProxy(context, isolate, env->as_callback_data())
.ToLocal(&env_var_proxy))
return MaybeLocal<Object>();

// process.env
process
->Set(env->context(),
FIXED_ONE_BYTE_STRING(env->isolate(), "env"),
env_var_proxy)
.FromJust();

READONLY_PROPERTY(process, "pid",
Integer::New(env->isolate(), uv_os_getpid()));

Expand Down

0 comments on commit 57d302b

Please sign in to comment.