@@ -167,7 +167,7 @@ static node_module* modlist_addon;
167
167
168
168
#if defined(NODE_HAVE_I18N_SUPPORT)
169
169
// 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)
171
171
#endif
172
172
173
173
// used by C++ modules as well
@@ -945,12 +945,21 @@ Local<Value> UVException(Isolate* isolate,
945
945
946
946
947
947
// 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 ) {
949
949
#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
+ }
952
956
#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 ;
954
963
}
955
964
956
965
@@ -3148,11 +3157,11 @@ void SetupProcessObject(Environment* env,
3148
3157
" icu" ,
3149
3158
OneByteString (env->isolate (), U_ICU_VERSION));
3150
3159
3151
- if (icu_data_dir != nullptr ) {
3160
+ if (!icu_data_dir. empty () ) {
3152
3161
// Did the user attempt (via env var or parameter) to set an ICU path?
3153
3162
READONLY_PROPERTY (process,
3154
3163
" icu_data_dir" ,
3155
- OneByteString (env->isolate (), icu_data_dir));
3164
+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
3156
3165
}
3157
3166
#endif
3158
3167
@@ -3873,7 +3882,7 @@ static void ParseArgs(int* argc,
3873
3882
#endif /* HAVE_OPENSSL */
3874
3883
#if defined(NODE_HAVE_I18N_SUPPORT)
3875
3884
} else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3876
- icu_data_dir = arg + 15 ;
3885
+ icu_data_dir. assign ( arg + 15 ) ;
3877
3886
#endif
3878
3887
} else if (strcmp (arg, " --expose-internals" ) == 0 ||
3879
3888
strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4390,12 +4399,11 @@ void Init(int* argc,
4390
4399
#endif
4391
4400
4392
4401
#if defined(NODE_HAVE_I18N_SUPPORT)
4393
- if (icu_data_dir == nullptr ) {
4394
- // if the parameter isn't given, use the env variable.
4395
- icu_data_dir = secure_getenv (" NODE_ICU_DATA" );
4396
- }
4402
+ // If the parameter isn't given, use the env variable.
4403
+ if (icu_data_dir.empty ())
4404
+ SafeGetenv (" NODE_ICU_DATA" , &icu_data_dir);
4397
4405
// Initialize ICU.
4398
- // If icu_data_dir is nullptr here, it will load the 'minimal' data.
4406
+ // If icu_data_dir is empty here, it will load the 'minimal' data.
4399
4407
if (!i18n::InitializeICUDirectory (icu_data_dir)) {
4400
4408
FatalError (nullptr , " Could not initialize ICU "
4401
4409
" (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4736,8 +4744,11 @@ int Start(int argc, char** argv) {
4736
4744
Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
4737
4745
4738
4746
#if HAVE_OPENSSL
4739
- if (const char * extra = secure_getenv (" NODE_EXTRA_CA_CERTS" ))
4740
- crypto::UseExtraCaCerts (extra);
4747
+ {
4748
+ std::string extra_ca_certs;
4749
+ if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
4750
+ crypto::UseExtraCaCerts (extra_ca_certs);
4751
+ }
4741
4752
#ifdef NODE_FIPS_MODE
4742
4753
// In the case of FIPS builds we should make sure
4743
4754
// the random source is properly initialized first.
@@ -4746,7 +4757,7 @@ int Start(int argc, char** argv) {
4746
4757
// V8 on Windows doesn't have a good source of entropy. Seed it from
4747
4758
// OpenSSL's pool.
4748
4759
V8::SetEntropySource (crypto::EntropySource);
4749
- #endif
4760
+ #endif // HAVE_OPENSSL
4750
4761
4751
4762
v8_platform.Initialize (v8_thread_pool_size);
4752
4763
V8::Initialize ();
0 commit comments