Skip to content

Commit d10c2c6

Browse files
bl-ueBethGriggs
authored andcommitted
src: fix empty-named env var assertion failure
Setting an environment variable with an empty name on Windows resulted in an assertion failure, because it was checked for an '=' sign at the beginning without verifying the length was greater than 0. Fixes: #32920 Refs: #27310 PR-URL: #32921 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent c84d802 commit d10c2c6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/node_env_var.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void RealEnvStore::Set(Isolate* isolate,
121121
node::Utf8Value val(isolate, value);
122122

123123
#ifdef _WIN32
124-
if (key[0] == L'=') return;
124+
if (key.length() > 0 && key[0] == L'=') return;
125125
#endif
126126
uv_os_setenv(*key, *val);
127127
DateTimeConfigurationChangeNotification(isolate, key);

test/parallel/test-process-env.js

+8
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,11 @@ if (common.isWindows) {
106106
const keys = Object.keys(process.env);
107107
assert.ok(keys.length > 0);
108108
}
109+
110+
// Setting environment variables on Windows with empty names should not cause
111+
// an assertion failure.
112+
// https://github.com/nodejs/node/issues/32920
113+
{
114+
process.env[''] = '';
115+
assert.strictEqual(process.env[''], undefined);
116+
}

0 commit comments

Comments
 (0)