Repository navigation
fix: reject out-of-range resultCode in GetLDAPError - #640
Merged
Merged
Conversation
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
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetLDAPErrornarrows 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.IsErrorWithCodedown the wrong branch.parseLDAPResultnarrows the same field intoSearchResult.ResultCodeandDigestMD5Bindcompares the narrowed value with 14, so 65550 is taken there for saslBindInProgress.packetResultCodebeside 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 inError.ResultCodecannot represent.Validation: a BindResponse carrying resultCode 65536 over the in-package fake connection makes
Conn.Bindreturn nil on master and the decode error after the change, and the new cases inerror_test.gofail on master.go vet,go buildandgo test -cover -race -count=1 ./...pass locally against themake local-serverdirectory.