@@ -34,22 +34,25 @@ bool linux_at_secure = false;
34
34
namespace credentials {
35
35
36
36
// 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) {
38
41
#if !defined(__CloudABI__) && !defined(_WIN32)
39
42
if (per_process::linux_at_secure || getuid () != geteuid () ||
40
43
getgid () != getegid ())
41
44
goto fail;
42
45
#endif
43
46
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 ());
50
53
Local<String> value;
51
54
if (!maybe_value.ToLocal (&value)) goto fail;
52
- String::Utf8Value utf8_value (env-> isolate () , value);
55
+ String::Utf8Value utf8_value (isolate, value);
53
56
if (*utf8_value == nullptr ) goto fail;
54
57
*text = std::string (*utf8_value, utf8_value.length ());
55
58
return true ;
@@ -86,7 +89,7 @@ static void SafeGetenv(const FunctionCallbackInfo<Value>& args) {
86
89
Isolate* isolate = env->isolate ();
87
90
Utf8Value strenvtag (isolate, args[0 ]);
88
91
std::string text;
89
- if (!SafeGetenv (*strenvtag, &text, env)) return ;
92
+ if (!SafeGetenv (*strenvtag, &text, env-> env_vars (), isolate )) return ;
90
93
Local<Value> result =
91
94
ToV8Value (isolate->GetCurrentContext (), text).ToLocalChecked ();
92
95
args.GetReturnValue ().Set (result);
0 commit comments