@@ -167,7 +167,7 @@ static node_module* modlist_addon;
167167
168168#if defined(NODE_HAVE_I18N_SUPPORT)
169169// Path to ICU data (for i18n / Intl)
170- static const char * icu_data_dir = nullptr ;
170+ static std::string icu_data_dir; // NOLINT(runtime/string)
171171#endif
172172
173173// used by C++ modules as well
@@ -945,12 +945,21 @@ Local<Value> UVException(Isolate* isolate,
945945
946946
947947// Look up environment variable unless running as setuid root.
948- inline const char * secure_getenv (const char * key) {
948+ inline bool SafeGetenv (const char * key, std::string* text ) {
949949#ifndef _WIN32
950- if (getuid () != geteuid () || getgid () != getegid ())
951- return nullptr ;
950+ // TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE)
951+ // is non-zero on Linux.
952+ if (getuid () != geteuid () || getgid () != getegid ()) {
953+ text->clear ();
954+ return false ;
955+ }
952956#endif
953- return getenv (key);
957+ if (const char * value = getenv (key)) {
958+ *text = value;
959+ return true ;
960+ }
961+ text->clear ();
962+ return false ;
954963}
955964
956965
@@ -3136,11 +3145,11 @@ void SetupProcessObject(Environment* env,
31363145 " icu" ,
31373146 OneByteString (env->isolate (), U_ICU_VERSION));
31383147
3139- if (icu_data_dir != nullptr ) {
3148+ if (!icu_data_dir. empty () ) {
31403149 // Did the user attempt (via env var or parameter) to set an ICU path?
31413150 READONLY_PROPERTY (process,
31423151 " icu_data_dir" ,
3143- OneByteString (env->isolate (), icu_data_dir));
3152+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
31443153 }
31453154#endif
31463155
@@ -3855,7 +3864,7 @@ static void ParseArgs(int* argc,
38553864#endif /* HAVE_OPENSSL */
38563865#if defined(NODE_HAVE_I18N_SUPPORT)
38573866 } else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3858- icu_data_dir = arg + 15 ;
3867+ icu_data_dir. assign ( arg + 15 ) ;
38593868#endif
38603869 } else if (strcmp (arg, " --expose-internals" ) == 0 ||
38613870 strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4372,12 +4381,11 @@ void Init(int* argc,
43724381#endif
43734382
43744383#if defined(NODE_HAVE_I18N_SUPPORT)
4375- if (icu_data_dir == nullptr ) {
4376- // if the parameter isn't given, use the env variable.
4377- icu_data_dir = secure_getenv (" NODE_ICU_DATA" );
4378- }
4384+ // If the parameter isn't given, use the env variable.
4385+ if (icu_data_dir.empty ())
4386+ SafeGetenv (" NODE_ICU_DATA" , &icu_data_dir);
43794387 // Initialize ICU.
4380- // If icu_data_dir is nullptr here, it will load the 'minimal' data.
4388+ // If icu_data_dir is empty here, it will load the 'minimal' data.
43814389 if (!i18n::InitializeICUDirectory (icu_data_dir)) {
43824390 FatalError (nullptr , " Could not initialize ICU "
43834391 " (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4718,8 +4726,11 @@ int Start(int argc, char** argv) {
47184726 Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
47194727
47204728#if HAVE_OPENSSL
4721- if (const char * extra = secure_getenv (" NODE_EXTRA_CA_CERTS" ))
4722- crypto::UseExtraCaCerts (extra);
4729+ {
4730+ std::string extra_ca_certs;
4731+ if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
4732+ crypto::UseExtraCaCerts (extra_ca_certs);
4733+ }
47234734#ifdef NODE_FIPS_MODE
47244735 // In the case of FIPS builds we should make sure
47254736 // the random source is properly initialized first.
@@ -4728,7 +4739,7 @@ int Start(int argc, char** argv) {
47284739 // V8 on Windows doesn't have a good source of entropy. Seed it from
47294740 // OpenSSL's pool.
47304741 V8::SetEntropySource (crypto::EntropySource);
4731- #endif
4742+ #endif // HAVE_OPENSSL
47324743
47334744 v8_platform.Initialize (v8_thread_pool_size);
47344745 V8::Initialize ();
0 commit comments