@@ -100,12 +100,7 @@ typedef int mode_t;
100100#else
101101#include < pthread.h>
102102#include < sys/resource.h> // getrlimit, setrlimit
103- #include < unistd.h> // setuid, getuid
104- #endif
105-
106- #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
107- #include < pwd.h> // getpwnam()
108- #include < grp.h> // getgrnam()
103+ #include < unistd.h> // STDIN_FILENO, STDERR_FILENO
109104#endif
110105
111106namespace node {
@@ -153,8 +148,6 @@ unsigned int reverted = 0;
153148
154149bool v8_initialized = false ;
155150
156- bool linux_at_secure = false ;
157-
158151// process-relative uptime base, initialized at start-up
159152double prog_start_time;
160153
@@ -501,27 +494,6 @@ const char* signo_string(int signo) {
501494 }
502495}
503496
504- // Look up environment variable unless running as setuid root.
505- bool SafeGetenv (const char * key, std::string* text) {
506- #if !defined(__CloudABI__) && !defined(_WIN32)
507- if (linux_at_secure || getuid () != geteuid () || getgid () != getegid ())
508- goto fail;
509- #endif
510-
511- {
512- Mutex::ScopedLock lock (environ_mutex);
513- if (const char * value = getenv (key)) {
514- *text = value;
515- return true ;
516- }
517- }
518-
519- fail:
520- text->clear ();
521- return false ;
522- }
523-
524-
525497void * ArrayBufferAllocator::Allocate (size_t size) {
526498 if (zero_fill_field_ || per_process_opts->zero_fill_all_buffers )
527499 return UncheckedCalloc (size);
@@ -1157,14 +1129,6 @@ void SetupProcessObject(Environment* env,
11571129 env->SetMethod (process, " dlopen" , binding::DLOpen);
11581130 env->SetMethod (process, " reallyExit" , Exit);
11591131 env->SetMethodNoSideEffect (process, " uptime" , Uptime);
1160-
1161- #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
1162- env->SetMethodNoSideEffect (process, " getuid" , GetUid);
1163- env->SetMethodNoSideEffect (process, " geteuid" , GetEUid);
1164- env->SetMethodNoSideEffect (process, " getgid" , GetGid);
1165- env->SetMethodNoSideEffect (process, " getegid" , GetEGid);
1166- env->SetMethodNoSideEffect (process, " getgroups" , GetGroups);
1167- #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)
11681132}
11691133
11701134
@@ -1625,37 +1589,40 @@ void Init(std::vector<std::string>* argv,
16251589 {
16261590 std::string text;
16271591 default_env_options->pending_deprecation =
1628- SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) && text[0 ] == ' 1' ;
1592+ credentials::SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) &&
1593+ text[0 ] == ' 1' ;
16291594 }
16301595
16311596 // Allow for environment set preserving symlinks.
16321597 {
16331598 std::string text;
16341599 default_env_options->preserve_symlinks =
1635- SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) && text[0 ] == ' 1' ;
1600+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) &&
1601+ text[0 ] == ' 1' ;
16361602 }
16371603
16381604 {
16391605 std::string text;
16401606 default_env_options->preserve_symlinks_main =
1641- SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) && text[0 ] == ' 1' ;
1607+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) &&
1608+ text[0 ] == ' 1' ;
16421609 }
16431610
16441611 if (default_env_options->redirect_warnings .empty ()) {
1645- SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1646- &default_env_options->redirect_warnings );
1612+ credentials:: SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1613+ &default_env_options->redirect_warnings );
16471614 }
16481615
16491616#if HAVE_OPENSSL
16501617 std::string* openssl_config = &per_process_opts->openssl_config ;
16511618 if (openssl_config->empty ()) {
1652- SafeGetenv (" OPENSSL_CONF" , openssl_config);
1619+ credentials:: SafeGetenv (" OPENSSL_CONF" , openssl_config);
16531620 }
16541621#endif
16551622
16561623#if !defined(NODE_WITHOUT_NODE_OPTIONS)
16571624 std::string node_options;
1658- if (SafeGetenv (" NODE_OPTIONS" , &node_options)) {
1625+ if (credentials:: SafeGetenv (" NODE_OPTIONS" , &node_options)) {
16591626 std::vector<std::string> env_argv;
16601627 // [0] is expected to be the program name, fill it in from the real argv.
16611628 env_argv.push_back (argv->at (0 ));
@@ -1687,7 +1654,7 @@ void Init(std::vector<std::string>* argv,
16871654#if defined(NODE_HAVE_I18N_SUPPORT)
16881655 // If the parameter isn't given, use the env variable.
16891656 if (per_process_opts->icu_data_dir .empty ())
1690- SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
1657+ credentials:: SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
16911658 // Initialize ICU.
16921659 // If icu_data_dir is empty here, it will load the 'minimal' data.
16931660 if (!i18n::InitializeICUDirectory (per_process_opts->icu_data_dir )) {
@@ -2095,7 +2062,7 @@ int Start(int argc, char** argv) {
20952062#if HAVE_OPENSSL
20962063 {
20972064 std::string extra_ca_certs;
2098- if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
2065+ if (credentials:: SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
20992066 crypto::UseExtraCaCerts (extra_ca_certs);
21002067 }
21012068#ifdef NODE_FIPS_MODE
0 commit comments