Browse Source

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>
v6.x-staging
Sam Roberts 7 years ago
committed by Myles Borins
parent
commit
ef722790fc
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 7
      src/node.cc
  2. 7
      src/node_config.cc
  3. 2
      src/node_internals.h

7
src/node.cc

@ -207,7 +207,7 @@ bool config_preserve_symlinks = false;
bool config_expose_internals = false; bool config_expose_internals = false;
// Set in node.cc by ParseArgs when --redirect-warnings= is used. // 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 // process-relative uptime base, initialized at start-up
static double prog_start_time; static double prog_start_time;
@ -4410,9 +4410,8 @@ void Init(int* argc,
if (openssl_config.empty()) if (openssl_config.empty())
SafeGetenv("OPENSSL_CONF", &openssl_config); SafeGetenv("OPENSSL_CONF", &openssl_config);
if (auto redirect_warnings = secure_getenv("NODE_REDIRECT_WARNINGS")) { if (config_warning_file.empty())
config_warning_file = redirect_warnings; SafeGetenv("NODE_REDIRECT_WARNINGS", &config_warning_file);
}
// Parse a few arguments which are specific to Node. // Parse a few arguments which are specific to Node.
int v8_argc; int v8_argc;

7
src/node_config.cc

@ -49,11 +49,12 @@ void InitConfig(Local<Object> target,
if (config_expose_internals) if (config_expose_internals)
READONLY_BOOLEAN_PROPERTY("exposeInternals"); READONLY_BOOLEAN_PROPERTY("exposeInternals");
if (config_warning_file != nullptr) { if (!config_warning_file.empty()) {
Local<String> name = OneByteString(env->isolate(), "warningFile"); Local<String> name = OneByteString(env->isolate(), "warningFile");
Local<String> value = String::NewFromUtf8(env->isolate(), Local<String> value = String::NewFromUtf8(env->isolate(),
config_warning_file, config_warning_file.data(),
v8::NewStringType::kNormal) v8::NewStringType::kNormal,
config_warning_file.size())
.ToLocalChecked(); .ToLocalChecked();
target->DefineOwnProperty(env->context(), name, value).FromJust(); target->DefineOwnProperty(env->context(), name, value).FromJust();
} }

2
src/node_internals.h

@ -52,7 +52,7 @@ extern bool config_expose_internals;
// Set in node.cc by ParseArgs when --redirect-warnings= is used. // Set in node.cc by ParseArgs when --redirect-warnings= is used.
// Used to redirect warning output to a file rather than sending // Used to redirect warning output to a file rather than sending
// it to stderr. // it to stderr.
extern const char* config_warning_file; extern std::string config_warning_file;
// Forward declaration // Forward declaration
class Environment; class Environment;

Loading…
Cancel
Save