@@ -156,7 +156,7 @@ static const char* trace_enabled_categories = nullptr;
156
156
157
157
#if defined(NODE_HAVE_I18N_SUPPORT)
158
158
// Path to ICU data (for i18n / Intl)
159
- static const char * icu_data_dir = nullptr ;
159
+ static std::string icu_data_dir; // NOLINT(runtime/string)
160
160
#endif
161
161
162
162
// used by C++ modules as well
@@ -189,7 +189,7 @@ bool trace_warnings = false;
189
189
bool config_preserve_symlinks = false ;
190
190
191
191
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
192
- const char * config_warning_file;
192
+ std::string config_warning_file; // NOLINT(runtime/string)
193
193
194
194
bool v8_initialized = false ;
195
195
@@ -924,12 +924,21 @@ Local<Value> UVException(Isolate* isolate,
924
924
925
925
926
926
// Look up environment variable unless running as setuid root.
927
- inline const char * secure_getenv (const char * key) {
927
+ inline bool SafeGetenv (const char * key, std::string* text ) {
928
928
#ifndef _WIN32
929
- if (getuid () != geteuid () || getgid () != getegid ())
930
- return nullptr ;
929
+ // TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE)
930
+ // is non-zero on Linux.
931
+ if (getuid () != geteuid () || getgid () != getegid ()) {
932
+ text->clear ();
933
+ return false ;
934
+ }
931
935
#endif
932
- return getenv (key);
936
+ if (const char * value = getenv (key)) {
937
+ *text = value;
938
+ return true ;
939
+ }
940
+ text->clear ();
941
+ return false ;
933
942
}
934
943
935
944
@@ -3089,11 +3098,11 @@ void SetupProcessObject(Environment* env,
3089
3098
#if defined(NODE_HAVE_I18N_SUPPORT) && defined(U_ICU_VERSION)
3090
3099
// ICU-related versions are now handled on the js side, see bootstrap_node.js
3091
3100
3092
- if (icu_data_dir != nullptr ) {
3101
+ if (!icu_data_dir. empty () ) {
3093
3102
// Did the user attempt (via env var or parameter) to set an ICU path?
3094
3103
READONLY_PROPERTY (process,
3095
3104
" icu_data_dir" ,
3096
- OneByteString (env->isolate (), icu_data_dir));
3105
+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
3097
3106
}
3098
3107
#endif
3099
3108
@@ -3741,7 +3750,7 @@ static void ParseArgs(int* argc,
3741
3750
#endif /* HAVE_OPENSSL */
3742
3751
#if defined(NODE_HAVE_I18N_SUPPORT)
3743
3752
} else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3744
- icu_data_dir = arg + 15 ;
3753
+ icu_data_dir. assign ( arg, 15 ) ;
3745
3754
#endif
3746
3755
} else if (strcmp (arg, " --expose-internals" ) == 0 ||
3747
3756
strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4228,13 +4237,14 @@ void Init(int* argc,
4228
4237
#endif
4229
4238
4230
4239
// Allow for environment set preserving symlinks.
4231
- if (auto preserve_symlinks = secure_getenv (" NODE_PRESERVE_SYMLINKS" )) {
4232
- config_preserve_symlinks = (*preserve_symlinks == ' 1' );
4240
+ {
4241
+ std::string text;
4242
+ config_preserve_symlinks =
4243
+ SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) && text[0 ] == ' 1' ;
4233
4244
}
4234
4245
4235
- if (auto redirect_warnings = secure_getenv (" NODE_REDIRECT_WARNINGS" )) {
4236
- config_warning_file = redirect_warnings;
4237
- }
4246
+ if (config_warning_file.empty ())
4247
+ SafeGetenv (" NODE_REDIRECT_WARNINGS" , &config_warning_file);
4238
4248
4239
4249
// Parse a few arguments which are specific to Node.
4240
4250
int v8_argc;
@@ -4262,12 +4272,11 @@ void Init(int* argc,
4262
4272
#endif
4263
4273
4264
4274
#if defined(NODE_HAVE_I18N_SUPPORT)
4265
- if (icu_data_dir == nullptr ) {
4266
- // if the parameter isn't given, use the env variable.
4267
- icu_data_dir = secure_getenv (" NODE_ICU_DATA" );
4268
- }
4275
+ // If the parameter isn't given, use the env variable.
4276
+ if (icu_data_dir.empty ())
4277
+ SafeGetenv (" NODE_ICU_DATA" , &icu_data_dir);
4269
4278
// Initialize ICU.
4270
- // If icu_data_dir is nullptr here, it will load the 'minimal' data.
4279
+ // If icu_data_dir is empty here, it will load the 'minimal' data.
4271
4280
if (!i18n::InitializeICUDirectory (icu_data_dir)) {
4272
4281
FatalError (nullptr , " Could not initialize ICU "
4273
4282
" (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4532,8 +4541,11 @@ int Start(int argc, char** argv) {
4532
4541
Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
4533
4542
4534
4543
#if HAVE_OPENSSL
4535
- if (const char * extra = secure_getenv (" NODE_EXTRA_CA_CERTS" ))
4536
- crypto::UseExtraCaCerts (extra);
4544
+ {
4545
+ std::string extra_ca_certs;
4546
+ if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
4547
+ crypto::UseExtraCaCerts (extra_ca_certs);
4548
+ }
4537
4549
#ifdef NODE_FIPS_MODE
4538
4550
// In the case of FIPS builds we should make sure
4539
4551
// the random source is properly initialized first.
@@ -4542,7 +4554,7 @@ int Start(int argc, char** argv) {
4542
4554
// V8 on Windows doesn't have a good source of entropy. Seed it from
4543
4555
// OpenSSL's pool.
4544
4556
V8::SetEntropySource (crypto::EntropySource);
4545
- #endif
4557
+ #endif // HAVE_OPENSSL
4546
4558
4547
4559
v8_platform.Initialize (v8_thread_pool_size);
4548
4560
// Enable tracing when argv has --trace-events-enabled.
0 commit comments