Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a7677bc
fs: use signed types for stat data
LiviaMedeiros Jul 18, 2022
b8e5873
src: use named struct instead of typedef
tniessen Jul 18, 2022
cc97a8d
meta: update AUTHORS
nodejs-github-bot Jul 18, 2022
822b9c3
util: add tokens to parseArgs
shadowspawn Jul 18, 2022
3933ce3
deps: update undici to 5.8.0
nodejs-github-bot Jul 18, 2022
d4a0d39
build: add .gitattributes for npm and other shims
hrishikesh-kadam Jul 19, 2022
a88e8e5
tools: update doc to highlight.js@11.6.0
nodejs-github-bot Jul 19, 2022
26c863d
test: ensure NODE_EXTRA_CA_CERTS not set before tests
KrayzeeKev Jul 20, 2022
5b253cc
doc: add security release specifics to releases.md
BethGriggs Jul 14, 2022
d6bc311
doc: mention Win 32-bit openssl build issue
RafaelGSS Jul 15, 2022
df9693d
tools: support versioned node shared libs on z/OS
alexcfyung Mar 8, 2022
bc376c9
tools: add support for using API key to vuln checking script
facutuesca Jul 20, 2022
212115c
child_process: do not need to count length when maxBuffer is Infinity
theanarkh Jul 21, 2022
07c8c4e
http: add drop request event for http server
theanarkh Jul 22, 2022
822fa99
tools: add verbose flag to inactive TSC finder
Trott Jul 22, 2022
e0a8a58
doc: add F3n67u to collaborators
F3n67u Jul 23, 2022
12da85a
doc: fix typo in http.md
airingursb Jul 23, 2022
fc872e5
deps: update hast-util-raw
MoLow Jul 23, 2022
d69b19b
test: simplify ReplStream.wait()
tniessen Jul 23, 2022
687b79a
dns: fix cares memory leak
theanarkh Jul 24, 2022
ad2da1f
dns: fix getServers return undefined
jiahao-si Jul 24, 2022
e297afb
cluster: send connection to other server when worker drop it
theanarkh Jul 24, 2022
a9ab465
stream: fix 0 transform hwm backpressure
ronag Jul 24, 2022
aff813f
util: remove unicode support todo for perf implications
Anemy Jul 24, 2022
34e2c9c
doc: remind backporter about v8_embedder_string
kvakil Jul 24, 2022
7e75216
process: use `defineProperty` instead of assignment
erights Jul 24, 2022
72995c0
meta: update `node-api` in label-pr-config
daeyeon Jul 24, 2022
0ed25c3
doc: fix typo in `src/crypto/README.md`
Jianru-Lin Jul 24, 2022
5cc7554
test: fix test http upload timeout
theanarkh Jul 24, 2022
95dbd86
deps: update corepack to 0.12.1
nodejs-github-bot Jul 24, 2022
ffecb8a
meta: update AUTHORS
nodejs-github-bot Jul 24, 2022
3c077ab
doc: clarify subprocess.stdout/in/err property
cola119 Jul 24, 2022
8339409
test: simplify test-tls-set-secure-context
tniessen Jul 24, 2022
75e60cb
test: work scheduled in process.nextTick can keep the event loop alive
andreubotella Jul 24, 2022
105453b
buffer: do not leak memory if buffer is too big
kvakil Jul 24, 2022
7acbe8f
trace_events: trace net connect event
theanarkh Jul 24, 2022
5e9bdb6
test: remove test-whatwg-events-add-event-listener-options-once.js
F3n67u Jul 24, 2022
e6048b0
inspector: set sampling interval before start
codebytere Jul 25, 2022
b957882
net: fix socket._getpeername
daeyeon Jul 25, 2022
24b4a59
doc: recommend git-node-v8
kvakil Jul 25, 2022
8744e6b
tools: add more options to track flaky tests
aduh95 Jul 25, 2022
122864f
doc: improve documentation for safe `Promise` statics alternatives
aduh95 Jul 25, 2022
7f33433
doc: inspector.close undefined in worker threads
kvakil Jul 16, 2022
23cab44
test: update WPT encoding tests
cola119 Jul 25, 2022
acc68c9
doc: update email and mailmap for BethGriggs
BethGriggs Jul 25, 2022
1073bee
src: pass only Isolate* and env_vars to EnabledDebugList::Parse()
RaisinTen Jul 15, 2022
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
Prev Previous commit
src: pass only Isolate* and env_vars to EnabledDebugList::Parse()
The function doesn't require access to the entire Environment object, so
this change just passes what it needs.

Addresses this TODO -
https://github.com/nodejs/node/blob/71691e53d601a4cf3eab3b33cebe4cc9f50c8470/src/env.cc#L372-L374

Signed-off-by: Darshan Sen <raisinten@gmail.com>

PR-URL: #43668
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
RaisinTen authored and targos committed Jul 31, 2022
commit 1073beeba45c6c567b93f751a4c20879b6185fd4
6 changes: 4 additions & 2 deletions src/debug_utils.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "debug_utils-inl.h" // NOLINT(build/include)
#include "env-inl.h"
#include "node_internals.h"
#include "util.h"

#ifdef __POSIX__
#if defined(__linux__)
Expand Down Expand Up @@ -58,9 +59,10 @@ namespace per_process {
EnabledDebugList enabled_debug_list;
}

void EnabledDebugList::Parse(Environment* env) {
void EnabledDebugList::Parse(std::shared_ptr<KVStore> env_vars,
v8::Isolate* isolate) {
std::string cats;
credentials::SafeGetenv("NODE_DEBUG_NATIVE", &cats, env);
credentials::SafeGetenv("NODE_DEBUG_NATIVE", &cats, env_vars, isolate);
Parse(cats, true);
}

Expand Down
10 changes: 6 additions & 4 deletions src/debug_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "async_wrap.h"
#include "util.h"

#include <algorithm>
#include <sstream>
Expand Down Expand Up @@ -66,10 +67,11 @@ class NODE_EXTERN_PRIVATE EnabledDebugList {
return enabled_[static_cast<int>(category)];
}

// Uses NODE_DEBUG_NATIVE to initialize the categories. When env is not a
// nullptr, the environment variables set in the Environment are used.
// Otherwise the system environment variables are used.
void Parse(Environment* env);
// Uses NODE_DEBUG_NATIVE to initialize the categories. The env_vars variable
// is parsed if it is not a nullptr, otherwise the system environment
// variables are parsed.
void Parse(std::shared_ptr<KVStore> env_vars = nullptr,
v8::Isolate* isolate = nullptr);

private:
// Set all categories matching cats to the value of enabled.
Expand Down
5 changes: 1 addition & 4 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,7 @@ Environment::Environment(IsolateData* isolate_data,
}

set_env_vars(per_process::system_environment);
// TODO(joyeecheung): pass Isolate* and env_vars to it instead of the entire
// env, when the recursive dependency inclusion in "debug-utils.h" is
// resolved.
enabled_debug_list_.Parse(this);
enabled_debug_list_.Parse(env_vars(), isolate);

// We create new copies of the per-Environment option sets, so that it is
// easier to modify them after Environment creation. The defaults are
Expand Down
28 changes: 0 additions & 28 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,34 +656,6 @@ struct ContextInfo {

class EnabledDebugList;

class KVStore {
public:
KVStore() = default;
virtual ~KVStore() = default;
KVStore(const KVStore&) = delete;
KVStore& operator=(const KVStore&) = delete;
KVStore(KVStore&&) = delete;
KVStore& operator=(KVStore&&) = delete;

virtual v8::MaybeLocal<v8::String> Get(v8::Isolate* isolate,
v8::Local<v8::String> key) const = 0;
virtual v8::Maybe<std::string> Get(const char* key) const = 0;
virtual void Set(v8::Isolate* isolate,
v8::Local<v8::String> key,
v8::Local<v8::String> value) = 0;
virtual int32_t Query(v8::Isolate* isolate,
v8::Local<v8::String> key) const = 0;
virtual int32_t Query(const char* key) const = 0;
virtual void Delete(v8::Isolate* isolate, v8::Local<v8::String> key) = 0;
virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0;

virtual std::shared_ptr<KVStore> Clone(v8::Isolate* isolate) const;
virtual v8::Maybe<bool> AssignFromObject(v8::Local<v8::Context> context,
v8::Local<v8::Object> entries);

static std::shared_ptr<KVStore> CreateMapKVStore();
};

namespace per_process {
extern std::shared_ptr<KVStore> system_environment;
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ InitializationResult InitializeOncePerProcess(

// Initialized the enabled list for Debug() calls with system
// environment variables.
per_process::enabled_debug_list.Parse(nullptr);
per_process::enabled_debug_list.Parse();

atexit(ResetStdio);

Expand Down
21 changes: 12 additions & 9 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ bool linux_at_secure = false;
namespace credentials {

// Look up environment variable unless running as setuid root.
bool SafeGetenv(const char* key, std::string* text, Environment* env) {
bool SafeGetenv(const char* key,
std::string* text,
std::shared_ptr<KVStore> env_vars,
v8::Isolate* isolate) {
#if !defined(__CloudABI__) && !defined(_WIN32)
if (per_process::linux_at_secure || getuid() != geteuid() ||
getgid() != getegid())
goto fail;
#endif

if (env != nullptr) {
HandleScope handle_scope(env->isolate());
TryCatch ignore_errors(env->isolate());
MaybeLocal<String> maybe_value = env->env_vars()->Get(
env->isolate(),
String::NewFromUtf8(env->isolate(), key).ToLocalChecked());
if (env_vars != nullptr) {
DCHECK_NOT_NULL(isolate);
HandleScope handle_scope(isolate);
TryCatch ignore_errors(isolate);
MaybeLocal<String> maybe_value = env_vars->Get(
isolate, String::NewFromUtf8(isolate, key).ToLocalChecked());
Local<String> value;
if (!maybe_value.ToLocal(&value)) goto fail;
String::Utf8Value utf8_value(env->isolate(), value);
String::Utf8Value utf8_value(isolate, value);
if (*utf8_value == nullptr) goto fail;
*text = std::string(*utf8_value, utf8_value.length());
return true;
Expand Down Expand Up @@ -86,7 +89,7 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = env->isolate();
Utf8Value strenvtag(isolate, args[0]);
std::string text;
if (!SafeGetenv(*strenvtag, &text, env)) return;
if (!SafeGetenv(*strenvtag, &text, env->env_vars(), isolate)) return;
Local<Value> result =
ToV8Value(isolate->GetCurrentContext(), text).ToLocalChecked();
args.GetReturnValue().Set(result);
Expand Down
5 changes: 4 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ class ThreadPoolWork {
#endif // defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)

namespace credentials {
bool SafeGetenv(const char* key, std::string* text, Environment* env = nullptr);
bool SafeGetenv(const char* key,
std::string* text,
std::shared_ptr<KVStore> env_vars = nullptr,
v8::Isolate* isolate = nullptr);
} // namespace credentials

void DefineZlibConstants(v8::Local<v8::Object> target);
Expand Down
28 changes: 28 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,34 @@ template <typename Inner, typename Outer>
constexpr ContainerOfHelper<Inner, Outer> ContainerOf(Inner Outer::*field,
Inner* pointer);

class KVStore {
public:
KVStore() = default;
virtual ~KVStore() = default;
KVStore(const KVStore&) = delete;
KVStore& operator=(const KVStore&) = delete;
KVStore(KVStore&&) = delete;
KVStore& operator=(KVStore&&) = delete;

virtual v8::MaybeLocal<v8::String> Get(v8::Isolate* isolate,
v8::Local<v8::String> key) const = 0;
virtual v8::Maybe<std::string> Get(const char* key) const = 0;
virtual void Set(v8::Isolate* isolate,
v8::Local<v8::String> key,
v8::Local<v8::String> value) = 0;
virtual int32_t Query(v8::Isolate* isolate,
v8::Local<v8::String> key) const = 0;
virtual int32_t Query(const char* key) const = 0;
virtual void Delete(v8::Isolate* isolate, v8::Local<v8::String> key) = 0;
virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0;

virtual std::shared_ptr<KVStore> Clone(v8::Isolate* isolate) const;
virtual v8::Maybe<bool> AssignFromObject(v8::Local<v8::Context> context,
v8::Local<v8::Object> entries);

static std::shared_ptr<KVStore> CreateMapKVStore();
};

// Convenience wrapper around v8::String::NewFromOneByte().
inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
const char* data,
Expand Down