Skip to content

Commit

Permalink
crypto: fix regression on randomFillSync
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <[email protected]>

Fixes: #35722
PR-URL: #35723
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Beth Griggs <[email protected]>
  • Loading branch information
jasnell authored and gireeshpunathil committed Oct 21, 2020
1 parent c2ceb15 commit 4cbcfae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function randomFillSync(buf, offset = 0, size) {

const job = new RandomBytesJob(
kCryptoJobSync,
buf.buffer || buf,
buf,
offset,
size);

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-crypto-randomfillsync-regression.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 4cbcfae

Please sign in to comment.