Skip to content

Commit ef72279

Browse files
sam-githubMylesBorins
authored andcommitted
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 #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]>
1 parent a10b476 commit ef72279

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/node.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ bool config_preserve_symlinks = false;
207207
bool config_expose_internals = false;
208208

209209
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
210-
const char* config_warning_file;
210+
std::string config_warning_file; // NOLINT(runtime/string)
211211

212212
// process-relative uptime base, initialized at start-up
213213
static double prog_start_time;
@@ -4410,9 +4410,8 @@ void Init(int* argc,
44104410
if (openssl_config.empty())
44114411
SafeGetenv("OPENSSL_CONF", &openssl_config);
44124412

4413-
if (auto redirect_warnings = secure_getenv("NODE_REDIRECT_WARNINGS")) {
4414-
config_warning_file = redirect_warnings;
4415-
}
4413+
if (config_warning_file.empty())
4414+
SafeGetenv("NODE_REDIRECT_WARNINGS", &config_warning_file);
44164415

44174416
// Parse a few arguments which are specific to Node.
44184417
int v8_argc;

src/node_config.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ void InitConfig(Local<Object> target,
4949
if (config_expose_internals)
5050
READONLY_BOOLEAN_PROPERTY("exposeInternals");
5151

52-
if (config_warning_file != nullptr) {
52+
if (!config_warning_file.empty()) {
5353
Local<String> name = OneByteString(env->isolate(), "warningFile");
5454
Local<String> value = String::NewFromUtf8(env->isolate(),
55-
config_warning_file,
56-
v8::NewStringType::kNormal)
55+
config_warning_file.data(),
56+
v8::NewStringType::kNormal,
57+
config_warning_file.size())
5758
.ToLocalChecked();
5859
target->DefineOwnProperty(env->context(), name, value).FromJust();
5960
}

src/node_internals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern bool config_expose_internals;
5252
// Set in node.cc by ParseArgs when --redirect-warnings= is used.
5353
// Used to redirect warning output to a file rather than sending
5454
// it to stderr.
55-
extern const char* config_warning_file;
55+
extern std::string config_warning_file;
5656

5757
// Forward declaration
5858
class Environment;

0 commit comments

Comments
 (0)