Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3915152

Browse filesBrowse files
santigimenoaduh95
authored andcommitted
crypto: fix checkPrime crash with large buffers
Fixes: #56512 PR-URL: #56559 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 6af5053 commit 3915152
Copy full SHA for 3915152

File tree

Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_random.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_random.cc
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Maybe<void> CheckPrimeTraits::AdditionalConfig(
176176
ArrayBufferOrViewContents<unsigned char> candidate(args[offset]);
177177

178178
params->candidate = BignumPointer(candidate.data(), candidate.size());
179+
if (!params->candidate) {
180+
ThrowCryptoError(
181+
Environment::GetCurrent(args), ERR_get_error(), "BignumPointer");
182+
return Nothing<void>();
183+
}
179184

180185
CHECK(args[offset + 1]->IsInt32()); // Checks
181186
params->checks = args[offset + 1].As<Int32>()->Value();
Collapse file

‎test/parallel/test-crypto-prime.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-crypto-prime.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ for (const checks of [-(2 ** 31), -1, 2 ** 31, 2 ** 32 - 1, 2 ** 32, 2 ** 50]) {
254254
});
255255
}
256256

257+
{
258+
const bytes = Buffer.alloc(67108864);
259+
bytes[0] = 0x1;
260+
assert.throws(() => checkPrime(bytes, common.mustNotCall()), {
261+
code: 'ERR_OSSL_BN_BIGNUM_TOO_LONG',
262+
message: /bignum too long/
263+
});
264+
assert.throws(() => checkPrimeSync(bytes), {
265+
code: 'ERR_OSSL_BN_BIGNUM_TOO_LONG',
266+
message: /bignum too long/
267+
});
268+
}
269+
257270
assert(!checkPrimeSync(Buffer.from([0x1])));
258271
assert(checkPrimeSync(Buffer.from([0x2])));
259272
assert(checkPrimeSync(Buffer.from([0x3])));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.