From ac2e8820c4c4188e54afa0cf0d9fea8ec823e15d Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 25 May 2017 13:32:37 -0400 Subject: [PATCH] src: reduce duplicate code in SafeGetenv() PR-URL: https://github.com/nodejs/node/pull/13220 Reviewed-By: Refael Ackermann Reviewed-By: Sam Roberts Reviewed-By: James M Snell Reviewed-By: Daniel Bevenius Reviewed-By: Michael Dawson --- src/node.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/node.cc b/src/node.cc index f2688f2ecf52d5..60fba9ad2fa553 100644 --- a/src/node.cc +++ b/src/node.cc @@ -975,19 +975,16 @@ Local 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; }