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);