summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-no-negative-allocation.js
diff options
context:
space:
mode:
authorZYSzys <17367077526@163.com>2019-02-17 21:59:10 +0800
committerAnna Henningsen <anna@addaleax.net>2019-02-21 22:08:53 +0100
commit6fb7baf935442a1ceddcd0a585892456438f95aa (patch)
tree0cacb7315eeda5389a6a4005064c183b17a82c5a /test/parallel/test-buffer-no-negative-allocation.js
parentdbfe14c8092ba914afc22d4ed8b0e1937c27ac25 (diff)
downloadandroid-node-v8-6fb7baf935442a1ceddcd0a585892456438f95aa.tar.gz
android-node-v8-6fb7baf935442a1ceddcd0a585892456438f95aa.tar.bz2
android-node-v8-6fb7baf935442a1ceddcd0a585892456438f95aa.zip
buffer: harden validation of buffer allocation size
This makes using `NaN` as the buffer size throw an error. Fixes: https://github.com/nodejs/node/issues/26151 PR-URL: https://github.com/nodejs/node/pull/26162 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-buffer-no-negative-allocation.js')
-rw-r--r--test/parallel/test-buffer-no-negative-allocation.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/test/parallel/test-buffer-no-negative-allocation.js b/test/parallel/test-buffer-no-negative-allocation.js
index b34477aa8c..3a4958c8f6 100644
--- a/test/parallel/test-buffer-no-negative-allocation.js
+++ b/test/parallel/test-buffer-no-negative-allocation.js
@@ -7,22 +7,26 @@ const msg = common.expectsError({
code: 'ERR_INVALID_OPT_VALUE',
type: RangeError,
message: /^The value "[^"]*" is invalid for option "size"$/
-}, 12);
+}, 16);
// Test that negative Buffer length inputs throw errors.
assert.throws(() => Buffer(-Buffer.poolSize), msg);
assert.throws(() => Buffer(-100), msg);
assert.throws(() => Buffer(-1), msg);
+assert.throws(() => Buffer(NaN), msg);
assert.throws(() => Buffer.alloc(-Buffer.poolSize), msg);
assert.throws(() => Buffer.alloc(-100), msg);
assert.throws(() => Buffer.alloc(-1), msg);
+assert.throws(() => Buffer.alloc(NaN), msg);
assert.throws(() => Buffer.allocUnsafe(-Buffer.poolSize), msg);
assert.throws(() => Buffer.allocUnsafe(-100), msg);
assert.throws(() => Buffer.allocUnsafe(-1), msg);
+assert.throws(() => Buffer.allocUnsafe(NaN), msg);
assert.throws(() => Buffer.allocUnsafeSlow(-Buffer.poolSize), msg);
assert.throws(() => Buffer.allocUnsafeSlow(-100), msg);
assert.throws(() => Buffer.allocUnsafeSlow(-1), msg);
+assert.throws(() => Buffer.allocUnsafeSlow(NaN), msg);