summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2017-10-10 16:17:34 -0700
committerMyles Borins <myles.borins@gmail.com>2017-10-25 04:09:42 -0400
commit68f698c05a2097afccdf22525b3e4d591d2c9fdf (patch)
treeaf364ad668f97d3bdcb276a0d941945f27c9071f /src
parent16802c0b647ce6633b20c55ce908b0869ec6b798 (diff)
downloadnode-new-68f698c05a2097afccdf22525b3e4d591d2c9fdf.tar.gz
src: use SafeGetenv() for NODE_REDIRECT_WARNINGS
Mutations of the environment can invalidate pointers to environment variables, so make `secure_getenv()` copy them out instead of returning pointers. This is the part of https://github.com/nodejs/node/pull/11051 that applies to be11fb48d2f1b3f6. This part wasn't backported to 6.x when #11051 was backported because the semver-minor introduction of NODE_REDIRECT_WARNINGS hadn't been backported yet. Now that the env var is backported, this last bit of #11051 is needed. PR-URL: https://github.com/nodejs/node/pull/12677 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/node.cc7
-rw-r--r--src/node_config.cc7
-rw-r--r--src/node_internals.h2
3 files changed, 8 insertions, 8 deletions
diff --git a/src/node.cc b/src/node.cc
index c5be22a725..4d21f97111 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -207,7 +207,7 @@ bool config_preserve_symlinks = false;
bool config_expose_internals = false;
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
-const char* config_warning_file;
+std::string config_warning_file; // NOLINT(runtime/string)
// process-relative uptime base, initialized at start-up
static double prog_start_time;
@@ -4410,9 +4410,8 @@ void Init(int* argc,
if (openssl_config.empty())
SafeGetenv("OPENSSL_CONF", &openssl_config);
- if (auto redirect_warnings = secure_getenv("NODE_REDIRECT_WARNINGS")) {
- config_warning_file = redirect_warnings;
- }
+ if (config_warning_file.empty())
+ SafeGetenv("NODE_REDIRECT_WARNINGS", &config_warning_file);
// Parse a few arguments which are specific to Node.
int v8_argc;
diff --git a/src/node_config.cc b/src/node_config.cc
index c80e3f640d..0e61847096 100644
--- a/src/node_config.cc
+++ b/src/node_config.cc
@@ -49,11 +49,12 @@ void InitConfig(Local<Object> target,
if (config_expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals");
- if (config_warning_file != nullptr) {
+ if (!config_warning_file.empty()) {
Local<String> name = OneByteString(env->isolate(), "warningFile");
Local<String> value = String::NewFromUtf8(env->isolate(),
- config_warning_file,
- v8::NewStringType::kNormal)
+ config_warning_file.data(),
+ v8::NewStringType::kNormal,
+ config_warning_file.size())
.ToLocalChecked();
target->DefineOwnProperty(env->context(), name, value).FromJust();
}
diff --git a/src/node_internals.h b/src/node_internals.h
index 642e61c2c2..adcb7f835a 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -52,7 +52,7 @@ extern bool config_expose_internals;
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
// Used to redirect warning output to a file rather than sending
// it to stderr.
-extern const char* config_warning_file;
+extern std::string config_warning_file;
// Forward declaration
class Environment;