@@ -34,22 +34,25 @@ bool linux_at_secure = false;
3434namespace credentials {
3535
3636// Look up environment variable unless running as setuid root.
37- bool SafeGetenv (const char * key, std::string* text, Environment* env) {
37+ bool SafeGetenv (const char * key,
38+ std::string* text,
39+ std::shared_ptr<KVStore> env_vars,
40+ v8::Isolate* isolate) {
3841#if !defined(__CloudABI__) && !defined(_WIN32)
3942 if (per_process::linux_at_secure || getuid () != geteuid () ||
4043 getgid () != getegid ())
4144 goto fail;
4245#endif
4346
44- if (env != nullptr ) {
45- HandleScope handle_scope (env-> isolate () );
46- TryCatch ignore_errors (env-> isolate () );
47- MaybeLocal<String> maybe_value = env-> env_vars ()-> Get (
48- env-> isolate (),
49- String::NewFromUtf8 (env-> isolate () , key).ToLocalChecked ());
47+ if (env_vars != nullptr ) {
48+ DCHECK_NOT_NULL ( isolate);
49+ HandleScope handle_scope ( isolate);
50+ TryCatch ignore_errors (isolate);
51+ MaybeLocal<String> maybe_value = env_vars-> Get (
52+ isolate, String::NewFromUtf8 (isolate, key).ToLocalChecked ());
5053 Local<String> value;
5154 if (!maybe_value.ToLocal (&value)) goto fail;
52- String::Utf8Value utf8_value (env-> isolate () , value);
55+ String::Utf8Value utf8_value (isolate, value);
5356 if (*utf8_value == nullptr ) goto fail;
5457 *text = std::string (*utf8_value, utf8_value.length ());
5558 return true ;
@@ -86,7 +89,7 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) {
8689 Isolate* isolate = env->isolate ();
8790 Utf8Value strenvtag (isolate, args[0 ]);
8891 std::string text;
89- if (!SafeGetenv (*strenvtag, &text, env)) return ;
92+ if (!SafeGetenv (*strenvtag, &text, env-> env_vars (), isolate )) return ;
9093 Local<Value> result =
9194 ToV8Value (isolate->GetCurrentContext (), text).ToLocalChecked ();
9295 args.GetReturnValue ().Set (result);
0 commit comments