From 56e5759aadc48129a33935b9de05b17151c1172e Mon Sep 17 00:00:00 2001 From: gustavoluvizotto Date: Fri, 3 May 2024 18:15:32 +0200 Subject: [PATCH] Fix LDAP GetError and LDAP search (#509) * When trying to parse ldap error, value can be nil --- error.go | 2 +- search.go | 6 +++++- v3/error.go | 2 +- v3/search.go | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/error.go b/error.go index 53c6d622..0014ffe2 100644 --- a/error.go +++ b/error.go @@ -220,7 +220,7 @@ func GetLDAPError(packet *ber.Packet) error { return &Error{ ResultCode: resultCode, MatchedDN: response.Children[1].Value.(string), - Err: fmt.Errorf("%s", response.Children[2].Value.(string)), + Err: fmt.Errorf("%v", response.Children[2].Value), Packet: packet, } } diff --git a/search.go b/search.go index b5550ba6..62be1054 100644 --- a/search.go +++ b/search.go @@ -579,9 +579,13 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) { return result, ErrSizeLimitExceeded } + attr := make([]*ber.Packet, 0) + if len(packet.Children[1].Children) > 1 { + attr = packet.Children[1].Children[1].Children + } entry := &Entry{ DN: packet.Children[1].Children[0].Value.(string), - Attributes: unpackAttributes(packet.Children[1].Children[1].Children), + Attributes: unpackAttributes(attr), } result.Entries = append(result.Entries, entry) case 5: diff --git a/v3/error.go b/v3/error.go index 53c6d622..0014ffe2 100644 --- a/v3/error.go +++ b/v3/error.go @@ -220,7 +220,7 @@ func GetLDAPError(packet *ber.Packet) error { return &Error{ ResultCode: resultCode, MatchedDN: response.Children[1].Value.(string), - Err: fmt.Errorf("%s", response.Children[2].Value.(string)), + Err: fmt.Errorf("%v", response.Children[2].Value), Packet: packet, } } diff --git a/v3/search.go b/v3/search.go index b5550ba6..62be1054 100644 --- a/v3/search.go +++ b/v3/search.go @@ -579,9 +579,13 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) { return result, ErrSizeLimitExceeded } + attr := make([]*ber.Packet, 0) + if len(packet.Children[1].Children) > 1 { + attr = packet.Children[1].Children[1].Children + } entry := &Entry{ DN: packet.Children[1].Children[0].Value.(string), - Attributes: unpackAttributes(packet.Children[1].Children[1].Children), + Attributes: unpackAttributes(attr), } result.Entries = append(result.Entries, entry) case 5: