Skip to content

Commit 045b1fd

Browse files
committed
Fix ExtendedResponse parsing
According to rfc4511 responseName field in ExtendedResponse is OPTIONAL. I hit the problem with parsing 2.16.840.1.113730.3.8.10.5 response without the fix.
1 parent 0935f92 commit 045b1fd

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

v3/extended.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ func (l *Conn) Extended(er *ExtendedRequest) (*ExtendedResponse, error) {
7676
return nil, err
7777
}
7878

79-
if len(packet.Children[1].Children) < 4 {
79+
if len(packet.Children[1].Children) < 3 {
8080
return nil, fmt.Errorf(
81-
"ldap: malformed extended response: expected 4 children, got %d",
81+
"ldap: malformed extended response: expected at least 3 children, got %d",
8282
len(packet.Children),
8383
)
8484
}
8585

86+
var name string
87+
88+
if len(packet.Children[1].Children) < 4 {
89+
name = er.Name
90+
} else {
91+
name = packet.Children[1].Children[3].Data.String()
92+
}
93+
8694
response := &ExtendedResponse{
87-
Name: packet.Children[1].Children[3].Data.String(),
95+
Name: name,
8896
Controls: make([]Control, 0),
8997
}
9098

0 commit comments

Comments
 (0)