@@ -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
@@ -504,27 +497,6 @@ const char* signo_string(int signo) {
504497 }
505498}
506499
507- // Look up environment variable unless running as setuid root.
508- bool SafeGetenv (const char * key, std::string* text) {
509- #if !defined(__CloudABI__) && !defined(_WIN32)
510- if (linux_at_secure || getuid () != geteuid () || getgid () != getegid ())
511- goto fail;
512- #endif
513-
514- {
515- Mutex::ScopedLock lock (environ_mutex);
516- if (const char * value = getenv (key)) {
517- *text = value;
518- return true ;
519- }
520- }
521-
522- fail:
523- text->clear ();
524- return false ;
525- }
526-
527-
528500void * ArrayBufferAllocator::Allocate (size_t size) {
529501 if (zero_fill_field_ || per_process_opts->zero_fill_all_buffers )
530502 return UncheckedCalloc (size);
@@ -1165,14 +1137,6 @@ void SetupProcessObject(Environment* env,
11651137 env->SetMethod (process, " dlopen" , binding::DLOpen);
11661138 env->SetMethod (process, " reallyExit" , Exit);
11671139 env->SetMethodNoSideEffect (process, " uptime" , Uptime);
1168-
1169- #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
1170- env->SetMethodNoSideEffect (process, " getuid" , GetUid);
1171- env->SetMethodNoSideEffect (process, " geteuid" , GetEUid);
1172- env->SetMethodNoSideEffect (process, " getgid" , GetGid);
1173- env->SetMethodNoSideEffect (process, " getegid" , GetEGid);
1174- env->SetMethodNoSideEffect (process, " getgroups" , GetGroups);
1175- #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)
11761140}
11771141
11781142
@@ -1633,37 +1597,40 @@ void Init(std::vector<std::string>* argv,
16331597 {
16341598 std::string text;
16351599 default_env_options->pending_deprecation =
1636- SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) && text[0 ] == ' 1' ;
1600+ credentials::SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) &&
1601+ text[0 ] == ' 1' ;
16371602 }
16381603
16391604 // Allow for environment set preserving symlinks.
16401605 {
16411606 std::string text;
16421607 default_env_options->preserve_symlinks =
1643- SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) && text[0 ] == ' 1' ;
1608+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) &&
1609+ text[0 ] == ' 1' ;
16441610 }
16451611
16461612 {
16471613 std::string text;
16481614 default_env_options->preserve_symlinks_main =
1649- SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) && text[0 ] == ' 1' ;
1615+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) &&
1616+ text[0 ] == ' 1' ;
16501617 }
16511618
16521619 if (default_env_options->redirect_warnings .empty ()) {
1653- SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1654- &default_env_options->redirect_warnings );
1620+ credentials:: SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1621+ &default_env_options->redirect_warnings );
16551622 }
16561623
16571624#if HAVE_OPENSSL
16581625 std::string* openssl_config = &per_process_opts->openssl_config ;
16591626 if (openssl_config->empty ()) {
1660- SafeGetenv (" OPENSSL_CONF" , openssl_config);
1627+ credentials:: SafeGetenv (" OPENSSL_CONF" , openssl_config);
16611628 }
16621629#endif
16631630
16641631#if !defined(NODE_WITHOUT_NODE_OPTIONS)
16651632 std::string node_options;
1666- if (SafeGetenv (" NODE_OPTIONS" , &node_options)) {
1633+ if (credentials:: SafeGetenv (" NODE_OPTIONS" , &node_options)) {
16671634 std::vector<std::string> env_argv;
16681635 // [0] is expected to be the program name, fill it in from the real argv.
16691636 env_argv.push_back (argv->at (0 ));
@@ -1695,7 +1662,7 @@ void Init(std::vector<std::string>* argv,
16951662#if defined(NODE_HAVE_I18N_SUPPORT)
16961663 // If the parameter isn't given, use the env variable.
16971664 if (per_process_opts->icu_data_dir .empty ())
1698- SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
1665+ credentials:: SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
16991666 // Initialize ICU.
17001667 // If icu_data_dir is empty here, it will load the 'minimal' data.
17011668 if (!i18n::InitializeICUDirectory (per_process_opts->icu_data_dir )) {
@@ -2103,7 +2070,7 @@ int Start(int argc, char** argv) {
21032070#if HAVE_OPENSSL
21042071 {
21052072 std::string extra_ca_certs;
2106- if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
2073+ if (credentials:: SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
21072074 crypto::UseExtraCaCerts (extra_ca_certs);
21082075 }
21092076#ifdef NODE_FIPS_MODE
0 commit comments