Skip to content

Commit

Permalink
Apply node tls crash patch fix found here: nodejs/node#49635
Browse files Browse the repository at this point in the history
  • Loading branch information
nromito committed Nov 16, 2023
1 parent d14bc25 commit 4074c1c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,17 @@ class NodeJsBuilder {
join(this.patchDir, 'push_registers_asm.cc.patch'));
}

async patchBugs() {
await patchFile(
this.nodePath('src', 'crypto', 'crypto_tls.cc'),
join(this.patchDir, 'crypto_tls.cc.patch')
);
}

async applyPatches() {
await this.patchThirdPartyMain();
await this.patchNodeCompileIssues();
await this.patchNodeCompileIssues();
await this.patchBugs();
}

printDiskUsage() {
Expand Down
34 changes: 34 additions & 0 deletions src/patch/18.15.0/crypto_tls.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 1643adf771dafce8034a00faacf98a2e57d5eebc Thu Oct 5 01:40:07 2023
fixes TLS segfault crash

--- a/src/crypto/crypto_tls.cc
+++ b/src/crypto/crypto_tls.cc
@@ -223,7 +223,7 @@ int SelectALPNCallback(
const unsigned char* in,
unsigned int inlen,
void* arg) {
- TLSWrap* w = static_cast<TLSWrap*>(arg);
+ TLSWrap* w = static_cast<TLSWrap*>(SSL_get_app_data(s));
if (w->alpn_callback_enabled_) {
Environment* env = w->env();
HandleScope handle_scope(env->isolate());
@@ -1293,7 +1293,8 @@ void TLSWrap::EnableALPNCb(const FunctionCallbackInfo<Value>& args) {
wrap->alpn_callback_enabled_ = true;

SSL* ssl = wrap->ssl_.get();
- SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(ssl), SelectALPNCallback, wrap);
+ SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
+ SSL_CTX_set_alpn_select_cb(ssl_ctx, SelectALPNCallback, nullptr);
}

void TLSWrap::GetServername(const FunctionCallbackInfo<Value>& args) {
@@ -1589,7 +1590,8 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
} else {
w->alpn_protos_ = std::vector<unsigned char>(
protos.data(), protos.data() + protos.length());
- SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(ssl), SelectALPNCallback, w);
+ SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
+ SSL_CTX_set_alpn_select_cb(ssl_ctx, SelectALPNCallback, nullptr);
}
}

0 comments on commit 4074c1c

Please sign in to comment.