Skip to content

Commit 83d1ca7

Browse files
committed
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 #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: #27234 Refs: #27224 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 09cdc37 commit 83d1ca7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/node_credentials.cc

+9
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,29 @@ static gid_t gid_by_name(Isolate* isolate, Local<Value> value) {
172172
}
173173

174174
static void GetUid(const FunctionCallbackInfo<Value>& args) {
175+
Environment* env = Environment::GetCurrent(args);
176+
CHECK(env->has_run_bootstrapping_code());
175177
// uid_t is an uint32_t on all supported platforms.
176178
args.GetReturnValue().Set(static_cast<uint32_t>(getuid()));
177179
}
178180

179181
static void GetGid(const FunctionCallbackInfo<Value>& args) {
182+
Environment* env = Environment::GetCurrent(args);
183+
CHECK(env->has_run_bootstrapping_code());
180184
// gid_t is an uint32_t on all supported platforms.
181185
args.GetReturnValue().Set(static_cast<uint32_t>(getgid()));
182186
}
183187

184188
static void GetEUid(const FunctionCallbackInfo<Value>& args) {
189+
Environment* env = Environment::GetCurrent(args);
190+
CHECK(env->has_run_bootstrapping_code());
185191
// uid_t is an uint32_t on all supported platforms.
186192
args.GetReturnValue().Set(static_cast<uint32_t>(geteuid()));
187193
}
188194

189195
static void GetEGid(const FunctionCallbackInfo<Value>& args) {
196+
Environment* env = Environment::GetCurrent(args);
197+
CHECK(env->has_run_bootstrapping_code());
190198
// gid_t is an uint32_t on all supported platforms.
191199
args.GetReturnValue().Set(static_cast<uint32_t>(getegid()));
192200
}
@@ -269,6 +277,7 @@ static void SetEUid(const FunctionCallbackInfo<Value>& args) {
269277

270278
static void GetGroups(const FunctionCallbackInfo<Value>& args) {
271279
Environment* env = Environment::GetCurrent(args);
280+
CHECK(env->has_run_bootstrapping_code());
272281

273282
int ngroups = getgroups(0, nullptr);
274283
if (ngroups == -1) return env->ThrowErrnoException(errno, "getgroups");

src/node_process_methods.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
118118

119119
static void Cwd(const FunctionCallbackInfo<Value>& args) {
120120
Environment* env = Environment::GetCurrent(args);
121+
CHECK(env->has_run_bootstrapping_code());
121122
char buf[CHDIR_BUFSIZE];
122123
size_t cwd_len = sizeof(buf);
123124
int err = uv_cwd(buf, &cwd_len);
@@ -226,12 +227,13 @@ static void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
226227
}
227228

228229
static void Umask(const FunctionCallbackInfo<Value>& args) {
229-
uint32_t old;
230-
230+
Environment* env = Environment::GetCurrent(args);
231+
CHECK(env->has_run_bootstrapping_code());
231232
CHECK_EQ(args.Length(), 1);
232233
CHECK(args[0]->IsUndefined() || args[0]->IsUint32());
233234
Mutex::ScopedLock scoped_lock(per_process::umask_mutex);
234235

236+
uint32_t old;
235237
if (args[0]->IsUndefined()) {
236238
old = umask(0);
237239
umask(static_cast<mode_t>(old));

0 commit comments

Comments
 (0)