@@ -64,7 +64,10 @@ bool HasOnly(int capability) {
64
64
// process only has the capability CAP_NET_BIND_SERVICE set. If the current
65
65
// process does not have any capabilities set and the process is running as
66
66
// 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) {
68
71
#if !defined(__CloudABI__) && !defined(_WIN32)
69
72
#if defined(__linux__)
70
73
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) {
76
79
goto fail;
77
80
#endif
78
81
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 ());
85
88
Local<String> value;
86
89
if (!maybe_value.ToLocal (&value)) goto fail;
87
- String::Utf8Value utf8_value (env-> isolate () , value);
90
+ String::Utf8Value utf8_value (isolate, value);
88
91
if (*utf8_value == nullptr ) goto fail;
89
92
*text = std::string (*utf8_value, utf8_value.length ());
90
93
return true ;
@@ -121,7 +124,7 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) {
121
124
Isolate* isolate = env->isolate ();
122
125
Utf8Value strenvtag (isolate, args[0 ]);
123
126
std::string text;
124
- if (!SafeGetenv (*strenvtag, &text, env)) return ;
127
+ if (!SafeGetenv (*strenvtag, &text, env-> env_vars (), isolate )) return ;
125
128
Local<Value> result =
126
129
ToV8Value (isolate->GetCurrentContext (), text).ToLocalChecked ();
127
130
args.GetReturnValue ().Set (result);
0 commit comments