summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-01-30 20:27:17 +0100
committerJames M Snell <jasnell@gmail.com>2018-02-02 09:46:34 -0800
commit6acb1a3df59222ae44e2848b76c91a72f7942360 (patch)
tree717722f82fff87b026798191a99364bf9696c0b9 /test
parent6e7992e8b89b55253e43181b4910e6cdbd01318f (diff)
downloadandroid-node-v8-6acb1a3df59222ae44e2848b76c91a72f7942360.tar.gz
android-node-v8-6acb1a3df59222ae44e2848b76c91a72f7942360.tar.bz2
android-node-v8-6acb1a3df59222ae44e2848b76c91a72f7942360.zip
process: fix reading zero-length env vars on win32
Up until now, Node did not clear the current error code attempting to read environment variables on Windows. Since checking the error code is the way we distinguish between missing and zero-length environment variables, this could lead to a false positive when the error code was still tainted. In the simplest case, accessing a missing variable and then a zero-length one would lead Node to believe that both calls yielded an error. Before: > process.env.I=''; process.env.Q; process.env.I undefined > process.env.I=''; /*process.env.Q;*/ process.env.I '' After: > process.env.I=''; process.env.Q; process.env.I '' > process.env.I=''; /*process.env.Q;*/ process.env.I '' This only affects Node 8 and above, since before 1aa595e5bd64241451b3884d3029b9b9aa97c42d we always constructed a `v8::String::Value` instance for passing the lookup key to the OS, which in in turn always made a heap allocation and therefore reset the error code. PR-URL: https://github.com/nodejs/node/pull/18463 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-process-env-windows-error-reset.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/parallel/test-process-env-windows-error-reset.js b/test/parallel/test-process-env-windows-error-reset.js
new file mode 100644
index 0000000000..59e5f287d8
--- /dev/null
+++ b/test/parallel/test-process-env-windows-error-reset.js
@@ -0,0 +1,22 @@
+'use strict';
+require('../common');
+const assert = require('assert');
+
+// This checks that after accessing a missing env var, a subsequent
+// env read will succeed even for empty variables.
+
+{
+ process.env.FOO = '';
+ process.env.NONEXISTENT_ENV_VAR;
+ const foo = process.env.FOO;
+
+ assert.strictEqual(foo, '');
+}
+
+{
+ process.env.FOO = '';
+ process.env.NONEXISTENT_ENV_VAR;
+ const hasFoo = 'FOO' in process.env;
+
+ assert.strictEqual(hasFoo, true);
+}