Skip to content

Commit b956635

Browse files
indutnyMyles Borins
authored and
Myles Borins
committed
tls: catch certCbDone exceptions
Catch and emit `certCbDone` exceptions instead of throwing them as `uncaughtException` and crashing the whole process. Fix: #6822 PR-URL: #6887 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 53a67ed commit b956635

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

lib/_tls_wrap.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ function oncertcb(info) {
184184
if (!self._handle)
185185
return self.destroy(new Error('Socket is closed'));
186186

187-
self._handle.certCbDone();
187+
try {
188+
self._handle.certCbDone();
189+
} catch (e) {
190+
self.destroy(e);
191+
}
188192
});
189193
});
190194
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
if (!process.features.tls_sni) {
4+
console.log('1..0 # Skipped: node compiled without OpenSSL or ' +
5+
'with old OpenSSL version.');
6+
return;
7+
}
8+
9+
const common = require('../common');
10+
const assert = require('assert');
11+
12+
if (!common.hasCrypto) {
13+
console.log('1..0 # Skipped: missing crypto');
14+
return;
15+
}
16+
17+
const tls = require('tls');
18+
19+
const options = {
20+
SNICallback: (name, callback) => {
21+
callback(null, tls.createSecureContext());
22+
}
23+
};
24+
25+
const server = tls.createServer(options, (c) => {
26+
common.fail('Should not be called');
27+
}).on('clientError', common.mustCall((err, c) => {
28+
assert(/SSL_use_certificate:passed a null parameter/i.test(err.message));
29+
server.close();
30+
})).listen(common.PORT, common.mustCall(() => {
31+
const c = tls.connect({
32+
port: common.PORT,
33+
rejectUnauthorized: false,
34+
servername: 'any.name'
35+
}, () => {
36+
common.fail('Should not be called');
37+
});
38+
39+
c.on('error', common.mustCall((err) => {
40+
assert(/socket hang up/.test(err.message));
41+
}));
42+
}));

0 commit comments

Comments
 (0)