Skip to content

Commit

Permalink
src: use SafeGetenv() for NODE_REDIRECT_WARNINGS
Browse files Browse the repository at this point in the history
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 #11051 that
applies to be11fb4.
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: #12677
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
sam-github authored and MylesBorins committed Oct 16, 2017
1 parent a10b476 commit ef72279
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ef72279

Please sign in to comment.