Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 9c6142d

Browse files
pulsejetjsumners
authored andcommitted
server: prevent crash on blank DN bind
1 parent 6ceef13 commit 9c6142d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,11 @@ Server.prototype._getHandlerChain = function _getHandlerChain (req) {
854854
}
855855

856856
// Otherwise, match via DN rules
857-
assert.ok(req.dn)
858857
const keys = this._sortedRouteKeys()
859858
let fallbackHandler = [noSuffixHandler]
860859
// invalid DNs in non-strict mode are routed to the default handler
861860
const testDN = (typeof (req.dn) === 'string') ? DN.fromString(req.dn) : req.dn
861+
assert.ok(testDN)
862862

863863
for (let i = 0; i < keys.length; i++) {
864864
const suffix = keys[i]

test/server.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ tap.test('bind/unbind identity anonymous', function (t) {
257257
})
258258
})
259259

260+
tap.test('does not crash on empty DN values', function (t) {
261+
const server = ldap.createServer({
262+
connectionRouter: function (c) {
263+
server.newConnection(c)
264+
server.emit('testconnection', c)
265+
}
266+
})
267+
268+
server.listen(t.context.sock, function () {
269+
const client = ldap.createClient({ socketPath: t.context.sock })
270+
server.once('testconnection', () => {
271+
client.bind('', 'pw', function (err) {
272+
t.ok(err, 'blank bind dn throws error')
273+
client.unbind(function () {
274+
server.close(() => t.end())
275+
})
276+
})
277+
})
278+
})
279+
})
280+
260281
tap.test('bind/unbind identity user', function (t) {
261282
const server = ldap.createServer({
262283
connectionRouter: function (c) {

0 commit comments

Comments
 (0)