Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: disallow calling env-dependent methods during bootstrap #27234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,29 @@ static gid_t gid_by_name(Isolate* isolate, Local<Value> value) {
}

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

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

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

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

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

int ngroups = getgroups(0, nullptr);
if (ngroups == -1) return env->ThrowErrnoException(errno, "getgroups");
Expand Down
6 changes: 4 additions & 2 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down