@@ -165,7 +165,7 @@ static node_module* modlist_addon;
165
165
166
166
#if defined(NODE_HAVE_I18N_SUPPORT)
167
167
// 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)
169
169
#endif
170
170
171
171
// used by C++ modules as well
@@ -943,12 +943,21 @@ Local<Value> UVException(Isolate* isolate,
943
943
944
944
945
945
// 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 ) {
947
947
#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
+ }
950
954
#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 ;
952
961
}
953
962
954
963
@@ -3131,11 +3140,11 @@ void SetupProcessObject(Environment* env,
3131
3140
" icu" ,
3132
3141
OneByteString (env->isolate (), U_ICU_VERSION));
3133
3142
3134
- if (icu_data_dir != nullptr ) {
3143
+ if (!icu_data_dir. empty () ) {
3135
3144
// Did the user attempt (via env var or parameter) to set an ICU path?
3136
3145
READONLY_PROPERTY (process,
3137
3146
" icu_data_dir" ,
3138
- OneByteString (env->isolate (), icu_data_dir));
3147
+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
3139
3148
}
3140
3149
#endif
3141
3150
@@ -3850,7 +3859,7 @@ static void ParseArgs(int* argc,
3850
3859
#endif /* HAVE_OPENSSL */
3851
3860
#if defined(NODE_HAVE_I18N_SUPPORT)
3852
3861
} else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3853
- icu_data_dir = arg + 15 ;
3862
+ icu_data_dir. assign ( arg + 15 ) ;
3854
3863
#endif
3855
3864
} else if (strcmp (arg, " --expose-internals" ) == 0 ||
3856
3865
strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4351,12 +4360,11 @@ void Init(int* argc,
4351
4360
#endif
4352
4361
4353
4362
#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);
4358
4366
// 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.
4360
4368
if (!i18n::InitializeICUDirectory (icu_data_dir)) {
4361
4369
FatalError (nullptr , " Could not initialize ICU "
4362
4370
" (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4707,8 +4715,11 @@ int Start(int argc, char** argv) {
4707
4715
Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
4708
4716
4709
4717
#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
+ }
4712
4723
#ifdef NODE_FIPS_MODE
4713
4724
// In the case of FIPS builds we should make sure
4714
4725
// the random source is properly initialized first.
@@ -4717,7 +4728,7 @@ int Start(int argc, char** argv) {
4717
4728
// V8 on Windows doesn't have a good source of entropy. Seed it from
4718
4729
// OpenSSL's pool.
4719
4730
V8::SetEntropySource (crypto::EntropySource);
4720
- #endif
4731
+ #endif // HAVE_OPENSSL
4721
4732
4722
4733
v8_platform.Initialize (v8_thread_pool_size);
4723
4734
V8::Initialize ();
0 commit comments