Skip to content

Commit ac2e882

Browse files
cjihrigjasnell
authored andcommitted
src: reduce duplicate code in SafeGetenv()
PR-URL: #13220 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 9fa1489 commit ac2e882

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/node.cc

+5-8
Original file line numberDiff line numberDiff line change
@@ -975,19 +975,16 @@ Local<Value> UVException(Isolate* isolate,
975975
// Look up environment variable unless running as setuid root.
976976
bool SafeGetenv(const char* key, std::string* text) {
977977
#ifndef _WIN32
978-
if (getuid() != geteuid() || getgid() != getegid()) {
979-
text->clear();
980-
return false;
981-
}
978+
if (linux_at_secure || getuid() != geteuid() || getgid() != getegid())
979+
goto fail;
982980
#endif
983-
if (linux_at_secure) {
984-
text->clear();
985-
return false;
986-
}
981+
987982
if (const char* value = getenv(key)) {
988983
*text = value;
989984
return true;
990985
}
986+
987+
fail:
991988
text->clear();
992989
return false;
993990
}

0 commit comments

Comments
 (0)