Skip to content

Commit

Permalink
src: reduce duplicate code in SafeGetenv()
Browse files Browse the repository at this point in the history
PR-URL: #13220
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
cjihrig authored and jasnell committed May 29, 2017
1 parent 9fa1489 commit ac2e882
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,19 +975,16 @@ Local<Value> UVException(Isolate* isolate,
// Look up environment variable unless running as setuid root.
bool SafeGetenv(const char* key, std::string* text) {
#ifndef _WIN32
if (getuid() != geteuid() || getgid() != getegid()) {
text->clear();
return false;
}
if (linux_at_secure || getuid() != geteuid() || getgid() != getegid())
goto fail;
#endif
if (linux_at_secure) {
text->clear();
return false;
}

if (const char* value = getenv(key)) {
*text = value;
return true;
}

fail:
text->clear();
return false;
}
Expand Down

0 comments on commit ac2e882

Please sign in to comment.