summaryrefslogtreecommitdiff
path: root/test/parallel/test-module-binding.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-11-07 21:28:13 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2017-11-09 12:57:16 +0100
commitf823d381e700ec152575ebd2cdc4420def690833 (patch)
tree83915ceb6c50388ab0aa4fa180e20077f146da22 /test/parallel/test-module-binding.js
parente5238ed030a06fa94e4574eff504777e173c9351 (diff)
downloadandroid-node-v8-f823d381e700ec152575ebd2cdc4420def690833.tar.gz
android-node-v8-f823d381e700ec152575ebd2cdc4420def690833.tar.bz2
android-node-v8-f823d381e700ec152575ebd2cdc4420def690833.zip
src: fix UB in InternalModuleReadFile()
`&vec[0]` is undefined behavior when `vec.size() == 0`. It is mostly academic because package.json files are not usually empty and because with most STL implementations it decays to something that is legal C++ as long as the result is not dereferenced, but better safe than sorry. Note that the tests don't actually fail because of that, I added them as sanity checks. PR-URL: https://github.com/nodejs/node/pull/16871 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-module-binding.js')
-rw-r--r--test/parallel/test-module-binding.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js
new file mode 100644
index 0000000000..ba11c3e47e
--- /dev/null
+++ b/test/parallel/test-module-binding.js
@@ -0,0 +1,9 @@
+'use strict';
+require('../common');
+const fixtures = require('../common/fixtures');
+const { internalModuleReadFile } = process.binding('fs');
+const { strictEqual } = require('assert');
+
+strictEqual(internalModuleReadFile('nosuchfile'), undefined);
+strictEqual(internalModuleReadFile(fixtures.path('empty.txt')), '');
+strictEqual(internalModuleReadFile(fixtures.path('empty-with-bom.txt')), '');