Skip to content

Commit c498a72

Browse files
sigvbengl
authored andcommitted
tls: avoid throw in onerror for bad TLSSocket obj
TLSWrap.onerror has a helpful debug() call built in to it. However in case of a malformed TLSSocket object, where the `_tlsOptions` value is an unexpected `undefined`, accessing `_tlsOptions.isServer` causes a TypeError to be thrown. This commit ensures that the debug() call properly logs the state as 'unknown', instead of the two 'server' and 'client' choices previously available. Additionally, onerror branching is adjusted to allow such `undefined` options object, by use of optional chaining. Other methods are not being adjusted, as such a case of `undefined` options is not viable during regular processing of the TLSSocket. Fixes: #41501 PR-URL: #41523 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent f5f790b commit c498a72

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎lib/_tls_wrap.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ function onocspresponse(resp) {
408408
functiononerror(err){
409409
constowner=this[owner_symbol];
410410
debug('%s onerror %s had? %j',
411-
owner._tlsOptions.isServer ? 'server' : 'client',err,
412-
owner._hadError);
411+
(typeofowner._tlsOptions==='object'&&owner._tlsOptions!==null) ?
412+
owner._tlsOptions.isServer ? 'server' : 'client' :
413+
'unknown',
414+
err,owner._hadError);
413415

414416
if(owner._hadError)
415417
return;
@@ -421,7 +423,7 @@ function onerror(err) {
421423
// When handshake fails control is not yet released,
422424
// so self._tlsError will return null instead of actual error
423425
owner.destroy(err);
424-
}elseif(owner._tlsOptions.isServer&&
426+
}elseif(owner._tlsOptions?.isServer&&
425427
owner._rejectUnauthorized&&
426428
RegExpPrototypeTest(/peerdidnotreturnacertificate/,
427429
err.message)){

0 commit comments

Comments
 (0)