@@ -64,7 +64,10 @@ bool HasOnly(int capability) {
6464// process only has the capability CAP_NET_BIND_SERVICE set. If the current
6565// process does not have any capabilities set and the process is running as
6666// setuid root then lookup will not be allowed.
67- bool SafeGetenv (const char * key, std::string* text, Environment* env) {
67+ bool SafeGetenv (const char * key,
68+ std::string* text,
69+ std::shared_ptr<KVStore> env_vars,
70+ v8::Isolate* isolate) {
6871#if !defined(__CloudABI__) && !defined(_WIN32)
6972#if defined(__linux__)
7073 if ((!HasOnly (CAP_NET_BIND_SERVICE) && per_process::linux_at_secure) ||
@@ -76,15 +79,15 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {
7679 goto fail;
7780#endif
7881
79- if (env != nullptr ) {
80- HandleScope handle_scope (env-> isolate () );
81- TryCatch ignore_errors (env-> isolate () );
82- MaybeLocal<String> maybe_value = env-> env_vars ()-> Get (
83- env-> isolate (),
84- String::NewFromUtf8 (env-> isolate () , key).ToLocalChecked ());
82+ if (env_vars != nullptr ) {
83+ DCHECK_NOT_NULL ( isolate);
84+ HandleScope handle_scope ( isolate);
85+ TryCatch ignore_errors (isolate);
86+ MaybeLocal<String> maybe_value = env_vars-> Get (
87+ isolate, String::NewFromUtf8 (isolate, key).ToLocalChecked ());
8588 Local<String> value;
8689 if (!maybe_value.ToLocal (&value)) goto fail;
87- String::Utf8Value utf8_value (env-> isolate () , value);
90+ String::Utf8Value utf8_value (isolate, value);
8891 if (*utf8_value == nullptr ) goto fail;
8992 *text = std::string (*utf8_value, utf8_value.length ());
9093 return true ;
@@ -121,7 +124,7 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) {
121124 Isolate* isolate = env->isolate ();
122125 Utf8Value strenvtag (isolate, args[0 ]);
123126 std::string text;
124- if (!SafeGetenv (*strenvtag, &text, env)) return ;
127+ if (!SafeGetenv (*strenvtag, &text, env-> env_vars (), isolate )) return ;
125128 Local<Value> result =
126129 ToV8Value (isolate->GetCurrentContext (), text).ToLocalChecked ();
127130 args.GetReturnValue ().Set (result);
0 commit comments