From 98cfdaf5600ab6f57377288ca3ba3d092844e76c Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 20 Oct 2020 09:59:24 -0700 Subject: [PATCH] crypto: fix regression on randomFillSync Signed-off-by: James M Snell Fixes: https://github.com/nodejs/node/issues/35722 --- lib/internal/crypto/random.js | 2 +- .../test-crypto-randomfillsync-regression.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-crypto-randomfillsync-regression.js diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index ae4111bbb07e8d..dca43647a6635a 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 00000000000000..7a378642588d9e --- /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);