vjeantet / ldapserver

Package ldapserver implements LDAP Server
MIT License
246 stars 93 forks source link

How to process first packet panic #18

Open youngcow opened 8 years ago

youngcow commented 8 years ago

Hi,

This library is very well. But when I send an incorrect byte in first packet, the process panic. How should I process this panic?

Thanks.

bigeagle commented 8 years ago

Hi youngcow,

It should make more sense if you put up an example.

Cheers,

bigeagle commented 8 years ago

Hi @youngcow,

Many web frameworks has a "panic recovery" middleware, such as https://github.com/gin-gonic/gin/blob/develop/recovery.go#L25 maybe we can add this middleware to ldapserver.

Cheers,

woopstar commented 6 years ago

Project is idle? Panic error still happens

2017/12/29 18:26:35 Listening on 127.0.0.1:10389
2017/12/29 18:26:36 Connection client [1] from 127.0.0.1:54998 accepted
2017/12/29 18:26:36 client 1 close()
2017/12/29 18:26:36 client 1 close() - stop reading from client
2017/12/29 18:26:36 client 1 close() - Abandon signal sent to processors
2017/12/29 18:26:36 client [1] request processors ended
2017/12/29 18:26:36 client [1] connection closed
panic: Expecting 0x30 as first byte, but got 0x16 instead

goroutine 4 [running]:
github.com/vjeantet/ldapserver.readTagAndLength(0xc4200660c0, 0xc42000c080, 0x30, 0x30, 0xc4200fe0c0, 0x1516ac0, 0x0, 0x0)
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/packet.go:89 +0x4ad
github.com/vjeantet/ldapserver.readLdapMessageBytes(0xc4200660c0, 0x15147b8, 0xc42002f678, 0x10122c8)
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/packet.go:54 +0x49
github.com/vjeantet/ldapserver.readMessagePacket(0xc4200660c0, 0xc4200fe0c0, 0x103417b, 0xc42002f6b0)
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/packet.go:18 +0x2f
github.com/vjeantet/ldapserver.(*client).ReadPacket(0xc420104100, 0x0, 0xc4200fe0c0, 0x0)
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/client.go:53 +0x33
github.com/vjeantet/ldapserver.(*client).serve(0xc420104100)
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/client.go:117 +0x1fb
created by github.com/vjeantet/ldapserver.(*Server).serve
    /Sourcecode/github/goipam/packages/src/github.com/vjeantet/ldapserver/server.go:110 +0x4a6

Tested with this

ldapsearch -Z -H ldaps://127.0.0.1:10389 -D "cn=ClientLookup" -w secret -x -b dc=test,dc=domain,dc=com "cn=Andreas Kruger"
vjeantet commented 6 years ago

Not idle

Thanks for the example, it will easier to fix

woopstar commented 6 years ago

For the ease of it, I'm just using the default complex example.

woopstar commented 6 years ago

Do we have any ETA on this? :)

dcrobbins commented 6 years ago

a trivial approach would be to recover client panics, like so:

go func() {
    defer func() {
        if err := recover(); err != nil {
            Logger.Printf("ldap client panic recovered: %v", err)
        }
    }()

    cli.serve()
}()
marcoacsilva commented 2 years ago

Any update?

marcoacsilva commented 2 years ago

A workaround solution for me was to create my own custom Listener, wrapping the server Listener, to validate the first Byte and drop the connection if it's not 0x30 during the Accept phase. It's ugly, but it does the trick. With this, I only serve LDAP messages, avoiding panic the server.