Skip to content

Fix panic on malformed LDAP responses#586

Merged
cpuschma merged 1 commit intogo-ldap:masterfrom
Bahtya:fix/panic-malformed-response
Apr 4, 2026
Merged

Fix panic on malformed LDAP responses#586
cpuschma merged 1 commit intogo-ldap:masterfrom
Bahtya:fix/panic-malformed-response

Conversation

@Bahtya
Copy link
Copy Markdown
Contributor

@Bahtya Bahtya commented Apr 4, 2026

Problem

Six operations (Add, Del, Compare, Modify, ModifyDN, PasswordModify) access packet.Children[1] without bounds checking. A malformed BER response with fewer than 2 children causes a panic (index out of range).

Issue #453 previously fixed GetLDAPError for the same class of bug, but these individual callers were never patched.

Fixes #585

Solution

Add len(packet.Children) < 2 guard before accessing packet.Children[1] in all seven affected call sites across six files:

  • v3/add.goAdd()
  • v3/del.goDel()
  • v3/compare.goCompare()
  • v3/modify.goModify() and ModifyWithResult()
  • v3/moddn.goModifyDN()
  • v3/passwdmodify.goPasswordModify()

Each now returns a descriptive error ("ldap: malformed response: expected at least 2 children, got N") instead of panicking.

Testing

The fix is purely defensive — existing tests should pass unchanged. A malformed packet with 0 or 1 children will now return an error instead of crashing.

Six operations (Add, Del, Compare, Modify, ModifyDN, PasswordModify)
access packet.Children[1] without bounds checking. A malformed BER
response with fewer than 2 children causes a panic (index out of range).

Add len(packet.Children) < 2 guard in all affected functions, returning
a descriptive error instead of panicking.

Fixes #585
@cpuschma cpuschma merged commit 5937e97 into go-ldap:master Apr 4, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

Incomplete fix from #453: Add, Del, Compare, Modify, ModifyDN, PasswordModify still panic on malformed responses

2 participants