Merge pull request #2309 from chris--young/ssl-err

Prevents bad ssl credentials from causing a crash
This commit is contained in:
Brian C 2020-08-18 08:23:55 -05:00 committed by GitHub
commit 61e4b7f03b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -85,7 +85,11 @@ class Connection extends EventEmitter {
if (net.isIP(host) === 0) {
options.servername = host
}
self.stream = tls.connect(options)
try {
self.stream = tls.connect(options)
} catch (err) {
return self.emit('error', err)
}
self.attachListeners(self.stream)
self.stream.on('error', reportStreamError)

View File

@ -0,0 +1,24 @@
'use strict'
const pg = require('../../../lib')
const helper = require('../test-helper')
const suite = new helper.Suite()
suite.test('bad ssl credentials do not cause crash', (done) => {
const config = {
ssl: {
ca: 'invalid_value',
key: 'invalid_value',
cert: 'invalid_value',
},
}
const client = new pg.Client(config)
client.connect((err) => {
assert(err)
client.end()
done()
})
})