diff options
author | James M Snell <jasnell@gmail.com> | 2020-10-20 09:59:24 -0700 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2020-10-21 11:17:58 +0100 |
commit | f5acc2d0301d828dfa82aa3920223a3c48512c25 (patch) | |
tree | a740c688f58f17b1fb33c8d829d53c0c57869463 | |
parent | 1efa87082bffa1bb5211a4258197debcabb33410 (diff) | |
download | node-new-f5acc2d0301d828dfa82aa3920223a3c48512c25.tar.gz |
crypto: fix regression on randomFillSync
Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: https://github.com/nodejs/node/issues/35722
PR-URL: https://github.com/nodejs/node/pull/35723
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
-rw-r--r-- | lib/internal/crypto/random.js | 2 | ||||
-rw-r--r-- | test/parallel/test-crypto-randomfillsync-regression.js | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index ae4111bbb0..dca43647a6 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -113,7 +113,7 @@ function randomFillSync(buf, offset = 0, size) { const job = new RandomBytesJob( kCryptoJobSync, - buf.buffer || buf, + buf, offset, size); diff --git a/test/parallel/test-crypto-randomfillsync-regression.js b/test/parallel/test-crypto-randomfillsync-regression.js new file mode 100644 index 0000000000..7a37864258 --- /dev/null +++ b/test/parallel/test-crypto-randomfillsync-regression.js @@ -0,0 +1,18 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const { randomFillSync } = require('crypto'); +const { notStrictEqual } = require('assert'); + +const ab = new ArrayBuffer(20); +const buf = Buffer.from(ab, 10); + +const before = buf.toString('hex'); + +randomFillSync(buf); + +const after = buf.toString('hex'); + +notStrictEqual(before, after); |