@@ -165,7 +165,7 @@ static node_module* modlist_addon;
165165
166166#if defined(NODE_HAVE_I18N_SUPPORT)
167167// Path to ICU data (for i18n / Intl)
168- static const char * icu_data_dir = nullptr ;
168+ static std::string icu_data_dir; // NOLINT(runtime/string)
169169#endif
170170
171171// used by C++ modules as well
@@ -943,12 +943,21 @@ Local<Value> UVException(Isolate* isolate,
943943
944944
945945// Look up environment variable unless running as setuid root.
946- inline const char * secure_getenv (const char * key) {
946+ inline bool SafeGetenv (const char * key, std::string* text ) {
947947#ifndef _WIN32
948- if (getuid () != geteuid () || getgid () != getegid ())
949- return nullptr ;
948+ // TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE)
949+ // is non-zero on Linux.
950+ if (getuid () != geteuid () || getgid () != getegid ()) {
951+ text->clear ();
952+ return false ;
953+ }
950954#endif
951- return getenv (key);
955+ if (const char * value = getenv (key)) {
956+ *text = value;
957+ return true ;
958+ }
959+ text->clear ();
960+ return false ;
952961}
953962
954963
@@ -3131,11 +3140,11 @@ void SetupProcessObject(Environment* env,
31313140 " icu" ,
31323141 OneByteString (env->isolate (), U_ICU_VERSION));
31333142
3134- if (icu_data_dir != nullptr ) {
3143+ if (!icu_data_dir. empty () ) {
31353144 // Did the user attempt (via env var or parameter) to set an ICU path?
31363145 READONLY_PROPERTY (process,
31373146 " icu_data_dir" ,
3138- OneByteString (env->isolate (), icu_data_dir));
3147+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
31393148 }
31403149#endif
31413150
@@ -3850,7 +3859,7 @@ static void ParseArgs(int* argc,
38503859#endif /* HAVE_OPENSSL */
38513860#if defined(NODE_HAVE_I18N_SUPPORT)
38523861 } else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3853- icu_data_dir = arg + 15 ;
3862+ icu_data_dir. assign ( arg + 15 ) ;
38543863#endif
38553864 } else if (strcmp (arg, " --expose-internals" ) == 0 ||
38563865 strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4351,12 +4360,11 @@ void Init(int* argc,
43514360#endif
43524361
43534362#if defined(NODE_HAVE_I18N_SUPPORT)
4354- if (icu_data_dir == nullptr ) {
4355- // if the parameter isn't given, use the env variable.
4356- icu_data_dir = secure_getenv (" NODE_ICU_DATA" );
4357- }
4363+ // If the parameter isn't given, use the env variable.
4364+ if (icu_data_dir.empty ())
4365+ SafeGetenv (" NODE_ICU_DATA" , &icu_data_dir);
43584366 // Initialize ICU.
4359- // If icu_data_dir is nullptr here, it will load the 'minimal' data.
4367+ // If icu_data_dir is empty here, it will load the 'minimal' data.
43604368 if (!i18n::InitializeICUDirectory (icu_data_dir)) {
43614369 FatalError (nullptr , " Could not initialize ICU "
43624370 " (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4707,8 +4715,11 @@ int Start(int argc, char** argv) {
47074715 Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
47084716
47094717#if HAVE_OPENSSL
4710- if (const char * extra = secure_getenv (" NODE_EXTRA_CA_CERTS" ))
4711- crypto::UseExtraCaCerts (extra);
4718+ {
4719+ std::string extra_ca_certs;
4720+ if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
4721+ crypto::UseExtraCaCerts (extra_ca_certs);
4722+ }
47124723#ifdef NODE_FIPS_MODE
47134724 // In the case of FIPS builds we should make sure
47144725 // the random source is properly initialized first.
@@ -4717,7 +4728,7 @@ int Start(int argc, char** argv) {
47174728 // V8 on Windows doesn't have a good source of entropy. Seed it from
47184729 // OpenSSL's pool.
47194730 V8::SetEntropySource (crypto::EntropySource);
4720- #endif
4731+ #endif // HAVE_OPENSSL
47214732
47224733 v8_platform.Initialize (v8_thread_pool_size);
47234734 V8::Initialize ();
0 commit comments