Skip to content

Commit b956635

Browse files
indutnyMyles Borins
authored andcommitted
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‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ function oncertcb(info){
184184
if(!self._handle)
185185
returnself.destroy(newError('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
}
Lines changed: 42 additions & 0 deletions
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+
constcommon=require('../common');
10+
constassert=require('assert');
11+
12+
if(!common.hasCrypto){
13+
console.log('1..0 # Skipped: missing crypto');
14+
return;
15+
}
16+
17+
consttls=require('tls');
18+
19+
constoptions={
20+
SNICallback: (name,callback)=>{
21+
callback(null,tls.createSecureContext());
22+
}
23+
};
24+
25+
constserver=tls.createServer(options,(c)=>{
26+
common.fail('Should not be called');
27+
}).on('clientError',common.mustCall((err,c)=>{
28+
assert(/SSL_use_certificate:passedanullparameter/i.test(err.message));
29+
server.close();
30+
})).listen(common.PORT,common.mustCall(()=>{
31+
constc=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(/sockethangup/.test(err.message));
41+
}));
42+
}));

0 commit comments

Comments
(0)