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

Program exiting with a panic when trying to do a simplebind with controls. #156

Closed
krishtk opened this issue Mar 27, 2018 · 11 comments
Closed

Comments

@krishtk
Copy link

krishtk commented Mar 27, 2018

I wrote a test program to check the password controls feature for my LDAP directory but it is failing when I am trying to run the code.

Some more info on this bug:
This happens only when the authentication is successful and when I am expecting to get some info on the pasword policy.

The same setup works when I use python library. It gives proper info but with this library I always end up with a panic.

If someone who understands the issue can point me in the right direction that would be more than enough.

My code:

var ldapServer = "acmewapp.stage.acme.com"
var ldapPort = uint16(636)

l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort), &tls.Config{InsecureSkipVerify: true})
//l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
if err != nil {
	fmt.Printf(err.Error())
	return
}
defer l.Close()

controls := []ldap.Control{}
controls = append(controls, ldap.NewControlBeheraPasswordPolicy())
bindRequest := ldap.NewSimpleBindRequest("cn=acmewapp,dc=stage,dc=acme,dc=com", "password!@#", controls)
r, err := l.SimpleBind(bindRequest)

ppolicyControl := ldap.FindControl(r.Controls, ldap.ControlTypeBeheraPasswordPolicy)
var ppolicy *ldap.ControlBeheraPasswordPolicy
if ppolicyControl != nil {
	ppolicy = ppolicyControl.(*ldap.ControlBeheraPasswordPolicy)
} else {
	fmt.Println("ppolicyControl response not available.\n")
}
if err != nil {
	fmt.Println("err simplebind request %s", err.Error())
	if ppolicy != nil && ppolicy.Error >= 0 {
		fmt.Println("ppolicy string %s", ppolicy.ErrorString)
	}
}

Error that I am seeing:

go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x460e9d]

goroutine 1 [running]:
runtime.panic(0x5b11e0, 0x7dbee8)
	/usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
gopkg.in/ldap%2ev2.DecodeControl(0xc2100798c0, 0x0, 0x0)
	/opt/wapp/golang/src/gopkg.in/ldap.v2/control.go:339 +0x97d
gopkg.in/ldap%2ev2.(*Conn).SimpleBind(0xc21000f640, 0xc210051480, 0x0, 0x0, 0x0)
	/opt/wapp/golang/src/gopkg.in/ldap.v2/bind.go:88 +0x5ba
main.main()
	/opt/wapp/golang/testproj/main.go:26 +0x46b

goroutine 6 [runnable]:
net.runtime_pollWait(0x7fb34da06180, 0x72, 0x0)
	/usr/lib/go/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0xc210047140, 0x72, 0x7fb34da050c0, 0xb)
	/usr/lib/go/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0xc210047140, 0xb, 0x7fb34da050c0)
	/usr/lib/go/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).Read(0xc2100470e0, 0xc210070000, 0x800, 0x800, 0x0, ...)
	/usr/lib/go/src/pkg/net/fd_unix.go:204 +0x2a0
net.(*conn).Read(0xc210000078, 0xc210070000, 0x800, 0x800, 0x47cd81, ...)
	/usr/lib/go/src/pkg/net/net.go:122 +0xc5
crypto/tls.(*block).readFromUntil(0xc21001e840, 0x7fb34da06278, 0xc210000078, 0x5, 0xc210000078, ...)
	/usr/lib/go/src/pkg/crypto/tls/conn.go:459 +0xb6
crypto/tls.(*Conn).readRecord(0xc210052780, 0x17, 0x0, 0xc2100007e0)
	/usr/lib/go/src/pkg/crypto/tls/conn.go:539 +0x107
crypto/tls.(*Conn).Read(0xc210052780, 0xc2100007e0, 0x1, 0x1, 0x0, ...)
	/usr/lib/go/src/pkg/crypto/tls/conn.go:897 +0x135
io.ReadAtLeast(0x7fb34da06608, 0xc210052780, 0xc2100007e0, 0x1, 0x1, ...)
	/usr/lib/go/src/pkg/io/io.go:288 +0xf6
io.ReadFull(0x7fb34da06608, 0xc210052780, 0xc2100007e0, 0x1, 0x1, ...)
	/usr/lib/go/src/pkg/io/io.go:306 +0x71
gopkg.in/asn1-ber%2ev1.readByte(0x7fb34da06608, 0xc210052780, 0x41f558, 0x7f3780, 0xa)
	/opt/wapp/golang/src/gopkg.in/asn1-ber.v1/util.go:7 +0x78
gopkg.in/asn1-ber%2ev1.readIdentifier(0x7fb34da06608, 0xc210052780, 0x4669f7, 0x56cea0, 0x2, ...)
	/opt/wapp/golang/src/gopkg.in/asn1-ber.v1/identifier.go:15 +0x6c
gopkg.in/asn1-ber%2ev1.readHeader(0x7fb34da06608, 0xc210052780, 0x0, 0x0, 0xc21000f000, ...)
	/opt/wapp/golang/src/gopkg.in/asn1-ber.v1/header.go:9 +0x6d
gopkg.in/asn1-ber%2ev1.readPacket(0x7fb34da06608, 0xc210052780, 0x5a1820, 0x5d6a60, 0xc200000000, ...)
	/opt/wapp/golang/src/gopkg.in/asn1-ber.v1/ber.go:276 +0x42
gopkg.in/asn1-ber%2ev1.ReadPacket(0x7fb34da06608, 0xc210052780, 0xc210052780, 0x7fb34da06608, 0xc210052780)
	/opt/wapp/golang/src/gopkg.in/asn1-ber.v1/ber.go:199 +0x31
gopkg.in/ldap%2ev2.(*Conn).reader(0xc21000f640)
	/opt/wapp/golang/src/gopkg.in/ldap.v2/conn.go:442 +0x111
created by gopkg.in/ldap%2ev2.(*Conn).Start
	/opt/wapp/golang/src/gopkg.in/ldap.v2/conn.go:155 +0x2e

goroutine 5 [syscall]:
runtime.goexit()
	/usr/lib/go/src/pkg/runtime/proc.c:1394
exit status 2

Any info on this would be helpful.

Thanks.

@zhunxun
Copy link

zhunxun commented May 9, 2018

How to solve this problem?

@krishnatejak
Copy link

No solution yet.

@vetinari
Copy link
Contributor

which version are you running?

cd $GOPATH/go/src/gopkg.in/ldap.v2 && git tag -l

@krishnatejak
Copy link

I was using the latest v2.5.1

@vetinari
Copy link
Contributor

ok... this may happen when the server sends a mis-encoded control:
https://github.com/go-ldap/ldap/blob/v2.5.1/control.go#L338-L339
the ber.DecodePacket() returns nil when there's an error decoding. We should switch to DecodePacketErr probably

@vetinari
Copy link
Contributor

Can you check if this works for you
vetinari@760755c

@zhunxun
Copy link

zhunxun commented May 16, 2018

image

image

image

image

@vetinari
Copy link
Contributor

please check #166

@krishnatejak
Copy link

Hey Vetinari the solutions above will solve the problem of the program exiting but it won't address the issue of me not getting the cotrols back. I have tried those changes myself before and it works. I will try the fix 166 and update you on my results.

@zhunxun
Copy link

zhunxun commented May 16, 2018

yet,can not getting the cotrols back.

@stefanmcshane
Copy link
Contributor

Closing as release v3.2.3 should address

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

5 participants