Skip to content

Commit

Permalink
Fix control packets being encoded when none exist on bind
Browse files Browse the repository at this point in the history
During the code reshuffle in go-ldap#126 at bind time a call to encodeControls
was added. Unfortunately, the safety check around calling it when there
are no controls to encode were omitted from this call (unlike in del.go
and search.go). As a result the packet was always getting control
characters added even if there were none to encode.

I also modified the checks in del.go and search.go to be a little safer;
rather than check for a nil slice, it also will do the right thing when
the slice is not nil but there are no entries.
  • Loading branch information
jefferai committed Dec 7, 2017
1 parent 0ae9f24 commit 69cb73b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (bindRequest *SimpleBindRequest) encode() *ber.Packet {
request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, bindRequest.Username, "User Name"))
request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, bindRequest.Password, "Password"))

request.AppendChild(encodeControls(bindRequest.Controls))
if len(bindRequest.Controls) > 0 {
request.AppendChild(encodeControls(bindRequest.Controls))
}

return request
}
Expand Down
2 changes: 1 addition & 1 deletion del.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (l *Conn) Del(delRequest *DelRequest) error {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
packet.AppendChild(delRequest.encode())
if delRequest.Controls != nil {
if len(delRequest.Controls) > 0 {
packet.AppendChild(encodeControls(delRequest.Controls))
}

Expand Down
2 changes: 1 addition & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) {
}
packet.AppendChild(encodedSearchRequest)
// encode search controls
if searchRequest.Controls != nil {
if len(searchRequest.Controls) > 0 {
packet.AppendChild(encodeControls(searchRequest.Controls))
}

Expand Down

0 comments on commit 69cb73b

Please sign in to comment.