crypto: fix potential null pointer dereference when BIO_meth_new() fails

This function can return null, which will make the calls to
BIO_meth_set_* trigger a null deref.
Even after fixing this, there is an issue with the
`BIOPointer::New(GetMethod())` call in `NodeBIO::New` because the
`New` method cannot handle a null pointer despite other code already
guarding for this
(e.g. the `NodeBIO::New` function already checks `bio`).
This patch solves the issues by adding more null checks.

PR-URL: https://github.com/nodejs/node/pull/61788
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Nora Dossche authored and Antoine du Hamel committed 2026-02-28 12:06:58 +01:00
1 parent 46a61922bd
commit 3337b095db
2 files changed
+2

No files matched your search

+1
View File
@@ -1470,6 +1470,7 @@ BIOPointer BIOPointer::NewSecMem() {
}
BIOPointer BIOPointer::New(const BIO_METHOD* method) {
if (method == nullptr) return {};
return BIOPointer(BIO_new(method));
}
+1
View File
@@ -226,6 +226,7 @@ const BIO_METHOD* NodeBIO::GetMethod() {
// Static initialization ensures that this is safe to use concurrently.
static const BIO_METHOD* method = [&]() {
BIO_METHOD* method = BIO_meth_new(BIO_TYPE_MEM, "node.js SSL buffer");
CHECK_NOT_NULL(method);
BIO_meth_set_write(method, Write);
BIO_meth_set_read(method, Read);
BIO_meth_set_puts(method, Puts);