aboutsummaryrefslogtreecommitdiff
path: root/src/node_process_methods.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-15 08:41:23 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-17 16:07:34 +0800
commit83d1ca7de95b884bcf188ed399056358e1d9d063 (patch)
treece7897be787a797a89d6415d2522a3ce96decc56 /src/node_process_methods.cc
parent09cdc3782488d2e6db09baf75b0dfa1f68e5dc4f (diff)
downloadandroid-node-v8-83d1ca7de95b884bcf188ed399056358e1d9d063.tar.gz
android-node-v8-83d1ca7de95b884bcf188ed399056358e1d9d063.tar.bz2
android-node-v8-83d1ca7de95b884bcf188ed399056358e1d9d063.zip
src: disallow calling env-dependent methods during bootstrap
These cannot be preserved correctly in v8 snapshot. Currently none of these are called during bootstrap, this adds assertions to make sure future contributors do not accidentally call these in the wrong time. Consider this, on the machine that builds releases: ``` process.cwd(); # "/home/iojs/build/workspace/" ``` If `process.cwd()` is cached as in https://github.com/nodejs/node/pull/27224, when the user downloads this binary to their machine: ``` $ cd ~/ $ pwd # "/User/foo" $ node -p "process.cwd()" # "/home/iojs/build/workspace/" ``` This patch only adds checks in methods that get states from the environment - it's not likely that the setters would be called during bootstrap, and if they are called, we'll just ignore them and whatever tests that test the change would fail when snapshot is enabled. However the getters may be called in order to persist information into strings and that would be harder to catch (the test is only likely to test the format of these strings which won't be useful). PR-URL: https://github.com/nodejs/node/pull/27234 Refs: https://github.com/nodejs/node/pull/27224 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_process_methods.cc')
-rw-r--r--src/node_process_methods.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc
index e53a5a7015..1f215eddc4 100644
--- a/src/node_process_methods.cc
+++ b/src/node_process_methods.cc
@@ -118,6 +118,7 @@ static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
static void Cwd(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
+ CHECK(env->has_run_bootstrapping_code());
char buf[CHDIR_BUFSIZE];
size_t cwd_len = sizeof(buf);
int err = uv_cwd(buf, &cwd_len);
@@ -226,12 +227,13 @@ static void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
}
static void Umask(const FunctionCallbackInfo<Value>& args) {
- uint32_t old;
-
+ Environment* env = Environment::GetCurrent(args);
+ CHECK(env->has_run_bootstrapping_code());
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsUndefined() || args[0]->IsUint32());
Mutex::ScopedLock scoped_lock(per_process::umask_mutex);
+ uint32_t old;
if (args[0]->IsUndefined()) {
old = umask(0);
umask(static_cast<mode_t>(old));