diff --git a/v3/add.go b/v3/add.go index 6d8854e0..ca4329b3 100644 --- a/v3/add.go +++ b/v3/add.go @@ -83,6 +83,9 @@ func (l *Conn) Add(addRequest *AddRequest) error { return err } + if len(packet.Children) < 2 { + return fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationAddResponse { err := GetLDAPError(packet) if err != nil { diff --git a/v3/compare.go b/v3/compare.go index a1cd760b..4ce669e0 100644 --- a/v3/compare.go +++ b/v3/compare.go @@ -46,6 +46,9 @@ func (l *Conn) Compare(dn, attribute, value string) (bool, error) { return false, err } + if len(packet.Children) < 2 { + return false, fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationCompareResponse { err := GetLDAPError(packet) diff --git a/v3/del.go b/v3/del.go index cb7a683f..076e6c51 100644 --- a/v3/del.go +++ b/v3/del.go @@ -52,6 +52,9 @@ func (l *Conn) Del(delRequest *DelRequest) error { return err } + if len(packet.Children) < 2 { + return fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationDelResponse { err := GetLDAPError(packet) if err != nil { diff --git a/v3/moddn.go b/v3/moddn.go index 84a6488e..92acea0b 100644 --- a/v3/moddn.go +++ b/v3/moddn.go @@ -89,6 +89,9 @@ func (l *Conn) ModifyDN(m *ModifyDNRequest) error { return err } + if len(packet.Children) < 2 { + return fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationModifyDNResponse { err := GetLDAPError(packet) if err != nil { diff --git a/v3/modify.go b/v3/modify.go index 0e501360..663be5fd 100644 --- a/v3/modify.go +++ b/v3/modify.go @@ -121,6 +121,9 @@ func (l *Conn) Modify(modifyRequest *ModifyRequest) error { return err } + if len(packet.Children) < 2 { + return fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationModifyResponse { err := GetLDAPError(packet) if err != nil { @@ -159,6 +162,10 @@ func (l *Conn) ModifyWithResult(modifyRequest *ModifyRequest) (*ModifyResult, er return nil, err } + if len(packet.Children) < 2 { + return nil, fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } + switch packet.Children[1].Tag { case ApplicationModifyResponse: if err = GetLDAPError(packet); err != nil { diff --git a/v3/passwdmodify.go b/v3/passwdmodify.go index 72a2351a..c79701a3 100644 --- a/v3/passwdmodify.go +++ b/v3/passwdmodify.go @@ -93,6 +93,9 @@ func (l *Conn) PasswordModify(passwordModifyRequest *PasswordModifyRequest) (*Pa result := &PasswordModifyResult{} + if len(packet.Children) < 2 { + return nil, fmt.Errorf("ldap: malformed response: expected at least 2 children, got %d", len(packet.Children)) + } if packet.Children[1].Tag == ApplicationExtendedResponse { if err = GetLDAPError(packet); err != nil { result.Referral = getReferral(err, packet)