@@ -156,7 +156,7 @@ static const char* trace_enabled_categories = nullptr;
156156
157157#if defined(NODE_HAVE_I18N_SUPPORT)
158158// 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)
160160#endif
161161
162162// used by C++ modules as well
@@ -189,7 +189,7 @@ bool trace_warnings = false;
189189bool config_preserve_symlinks = false ;
190190
191191// 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)
193193
194194bool v8_initialized = false ;
195195
@@ -924,12 +924,21 @@ Local<Value> UVException(Isolate* isolate,
924924
925925
926926// 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 ) {
928928#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+ }
931935#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 ;
933942}
934943
935944
@@ -3089,11 +3098,11 @@ void SetupProcessObject(Environment* env,
30893098#if defined(NODE_HAVE_I18N_SUPPORT) && defined(U_ICU_VERSION)
30903099 // ICU-related versions are now handled on the js side, see bootstrap_node.js
30913100
3092- if (icu_data_dir != nullptr ) {
3101+ if (!icu_data_dir. empty () ) {
30933102 // Did the user attempt (via env var or parameter) to set an ICU path?
30943103 READONLY_PROPERTY (process,
30953104 " icu_data_dir" ,
3096- OneByteString (env->isolate (), icu_data_dir));
3105+ OneByteString (env->isolate (), icu_data_dir. c_str () ));
30973106 }
30983107#endif
30993108
@@ -3741,7 +3750,7 @@ static void ParseArgs(int* argc,
37413750#endif /* HAVE_OPENSSL */
37423751#if defined(NODE_HAVE_I18N_SUPPORT)
37433752 } else if (strncmp (arg, " --icu-data-dir=" , 15 ) == 0 ) {
3744- icu_data_dir = arg + 15 ;
3753+ icu_data_dir. assign ( arg, 15 ) ;
37453754#endif
37463755 } else if (strcmp (arg, " --expose-internals" ) == 0 ||
37473756 strcmp (arg, " --expose_internals" ) == 0 ) {
@@ -4228,13 +4237,14 @@ void Init(int* argc,
42284237#endif
42294238
42304239 // 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' ;
42334244 }
42344245
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);
42384248
42394249 // Parse a few arguments which are specific to Node.
42404250 int v8_argc;
@@ -4262,12 +4272,11 @@ void Init(int* argc,
42624272#endif
42634273
42644274#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);
42694278 // 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.
42714280 if (!i18n::InitializeICUDirectory (icu_data_dir)) {
42724281 FatalError (nullptr , " Could not initialize ICU "
42734282 " (check NODE_ICU_DATA or --icu-data-dir parameters)" );
@@ -4532,8 +4541,11 @@ int Start(int argc, char** argv) {
45324541 Init (&argc, const_cast <const char **>(argv), &exec_argc, &exec_argv);
45334542
45344543#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+ }
45374549#ifdef NODE_FIPS_MODE
45384550 // In the case of FIPS builds we should make sure
45394551 // the random source is properly initialized first.
@@ -4542,7 +4554,7 @@ int Start(int argc, char** argv) {
45424554 // V8 on Windows doesn't have a good source of entropy. Seed it from
45434555 // OpenSSL's pool.
45444556 V8::SetEntropySource (crypto::EntropySource);
4545- #endif
4557+ #endif // HAVE_OPENSSL
45464558
45474559 v8_platform.Initialize (v8_thread_pool_size);
45484560 // Enable tracing when argv has --trace-events-enabled.
0 commit comments