Skip to content

fix: reject out-of-range resultCode in GetLDAPError - #640

Merged
cpuschma merged 1 commit into
go-ldap:masterfrom
netliomax25-code:result-code-range-check
Oct 7, 2026
Merged

cpuschma merged 1 commit into
go-ldap:masterfrom
netliomax25-code:result-code-range-check

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. GetLDAPError narrows the server's resultCode from int64 to uint16 before testing it for success, so a code whose low 16 bits are zero (65536, 131072, or a negative multiple) is read as 0 and the function returns nil.
  2. It is the single place where Bind, Add, Del, Modify, ModifyDN, Compare, Extended and Search decide whether a reply failed, so such a reply reaches the caller as a successful operation, and a value like 65586 is aliased onto 50 (insufficientAccessRights), which also sends IsErrorWithCode down the wrong branch.
  3. parseLDAPResult narrows the same field into SearchResult.ResultCode and DigestMD5Bind compares the narrowed value with 14, so 65550 is taken there for saslBindInProgress.
  4. Added packetResultCode beside the other guarded leaf conversions and used it at those three sites, so an out-of-range code takes the existing "invalid result code in packet" path; RFC 4511 section 4.1.9 asks clients to cope with unrecognized codes and those are untouched, since the check only rejects what the uint16 in Error.ResultCode cannot represent.

Validation: a BindResponse carrying resultCode 65536 over the in-package fake connection makes Conn.Bind return nil on master and the decode error after the change, and the new cases in error_test.go fail on master. go vet, go build and go test -cover -race -count=1 ./... pass locally against the make local-server directory.

A resultCode whose low 16 bits are zero narrowed to success(0), so GetLDAPError returned nil for a reply that carried no success code. Read it as int64 and report a malformed packet when it does not fit the uint16 the package exposes.
@cpuschma cpuschma self-assigned this Oct 7, 2026
@cpuschma cpuschma added enhancement go Pull requests that update go code labels Oct 7, 2026
@cpuschma
cpuschma merged commit f3f0153 into go-ldap:master Oct 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants