Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to process first packet panic #18

Open
youngcow opened this issue Jul 26, 2016 · 9 comments
Open

How to process first packet panic #18

youngcow opened this issue Jul 26, 2016 · 9 comments

Comments

@youngcow
Copy link

youngcow commented Jul 26, 2016

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
Copy link

Hi youngcow,

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

Cheers,

@bigeagle
Copy link

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
Copy link

woopstar commented Dec 29, 2017

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
Copy link
Owner

Not idle

Thanks for the example, it will easier to fix

@woopstar
Copy link

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

@woopstar
Copy link

woopstar commented Jan 2, 2018

Do we have any ETA on this? :)

@dcrobbins
Copy link

dcrobbins commented Feb 23, 2018

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
Copy link

Any update?

@marcoacsilva
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants