@@ -154,7 +154,7 @@ static node_module* modlist_addon;
154
154
155
155
#if defined(NODE_HAVE_I18N_SUPPORT)
156
156
// Path to ICU data (for i18n / Intl)
157
- static const char * icu_data_dir = nullptr ;
157
+ static std::string icu_data_dir; // NOLINT(runtime/string)
158
158
#endif
159
159
160
160
// used by C++ modules as well
@@ -901,12 +901,21 @@ Local<Value> UVException(Isolate* isolate,
901
901
902
902
903
903
// Look up environment variable unless running as setuid root.
904
- inline const char * secure_getenv (const char * key) {
904
+ inline bool SafeGetenv (const char * key, std::string* text ) {
905
905
#ifndef _WIN32
906
- if (getuid () != geteuid () || getgid () != getegid ())
907
- return nullptr ;
906
+ // TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE)
907
+ // is non-zero on Linux.
908
+ if (getuid () != geteuid () || getgid () != getegid ()) {
909
+ text->clear ();
910
+ return false ;
911
+ }
908
912
#endif
909
- return getenv (key);
913
+ if (const char * value = getenv (key)) {
914
+ *text = value;
915
+ return true ;
916
+ }
917
+ text->clear ();
918
+ return false ;
910
919
}
911
920
912
921
@@ -3061,11 +3070,11 @@ void SetupProcessObject(Environment* env,
3061
3070
#if defined(NODE_HAVE_I18N_SUPPORT) && defined(U_ICU_VERSION)
3062
3071
// ICU-related versions are now handled on the js side, see bootstrap_node.js
3063
3072
3064
- if (icu_data_dir != nullptr ) {
3073
+ if (!icu_data_dir. empty () ) {
3065
3074
// Did the user attempt (via env var or parameter) to set an ICU path?
3066
3075
READONLY_PROPERTY (process,
3067
3076
" icu_data_dir" ,
3068
- OneByteString (env->isolate (), icu_data_dir));
3077
+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
3069
3078
}
3070
3079
#endif
3071
3080
@@ -3694,7 +3703,7 @@ static void ParseArgs(int* argc,
3694
3703
#endif /* HAVE_OPENSSL */
3695
3704
#if defined(NODE_HAVE_I18N_SUPPORT)
3696
3705
} else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3697
- icu_data_dir = arg + 15 ;
3706
+ icu_data_dir. assign ( arg, 15 ) ;
3698
3707
#endif
3699
3708
} else if (strcmp (arg, " --expose-internals" ) == 0 ||
3700
3709
strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4181,8 +4190,10 @@ void Init(int* argc,
4181
4190
#endif
4182
4191
4183
4192
// Allow for environment set preserving symlinks.
4184
- if (auto preserve_symlinks = secure_getenv (" NODE_PRESERVE_SYMLINKS" )) {
4185
- config_preserve_symlinks = (*preserve_symlinks == ' 1' );
4193
+ {
4194
+ std::string text;
4195
+ config_preserve_symlinks =
4196
+ SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) && text[0 ] == ' 1' ;
4186
4197
}
4187
4198
4188
4199
// Parse a few arguments which are specific to Node.
@@ -4211,12 +4222,11 @@ void Init(int* argc,
4211
4222
#endif
4212
4223
4213
4224
#if defined(NODE_HAVE_I18N_SUPPORT)
4214
- if (icu_data_dir == nullptr ) {
4215
- // if the parameter isn't given, use the env variable.
4216
- icu_data_dir = secure_getenv (" NODE_ICU_DATA" );
4217
- }
4225
+ // If the parameter isn't given, use the env variable.
4226
+ if (icu_data_dir.empty ())
4227
+ SafeGetenv (" NODE_ICU_DATA" , &icu_data_dir);
4218
4228
// Initialize ICU.
4219
- // If icu_data_dir is nullptr here, it will load the 'minimal' data.
4229
+ // If icu_data_dir is empty here, it will load the 'minimal' data.
4220
4230
if (!i18n::InitializeICUDirectory (icu_data_dir)) {
4221
4231
FatalError (nullptr , " Could not initialize ICU "
4222
4232
" (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4481,8 +4491,11 @@ int Start(int argc, char** argv) {
4481
4491
Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
4482
4492
4483
4493
#if HAVE_OPENSSL
4484
- if (const char * extra = secure_getenv (" NODE_EXTRA_CA_CERTS" ))
4485
- crypto::UseExtraCaCerts (extra);
4494
+ {
4495
+ std::string extra_ca_certs;
4496
+ if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
4497
+ crypto::UseExtraCaCerts (extra_ca_certs);
4498
+ }
4486
4499
#ifdef NODE_FIPS_MODE
4487
4500
// In the case of FIPS builds we should make sure
4488
4501
// the random source is properly initialized first.
@@ -4491,7 +4504,7 @@ int Start(int argc, char** argv) {
4491
4504
// V8 on Windows doesn't have a good source of entropy. Seed it from
4492
4505
// OpenSSL's pool.
4493
4506
V8::SetEntropySource (crypto::EntropySource);
4494
- #endif
4507
+ #endif // HAVE_OPENSSL
4495
4508
4496
4509
v8_platform.Initialize (v8_thread_pool_size);
4497
4510
V8::Initialize ();
0 commit comments