guard malformed attribute in unpackAttributes - #612
Merged
cpuschma merged 2 commits intoAug 10, 2026
Conversation
Contributor
Author
|
any update? |
cpuschma
requested changes
Jul 5, 2026
| // non-string type/value; index and assert defensively so a malformed | ||
| // attribute is skipped instead of panicking the search goroutine. | ||
| if len(child.Children) < 2 { | ||
| continue |
Member
There was a problem hiding this comment.
Discarding the PartialAttribute without throwing an error because of a non-conforming result is undefined behaviour compared to the LDAPv3 RFC. I'd suggest to throw an error instead and allow the user to handle it.
Contributor
Author
There was a problem hiding this comment.
Makes sense. Pushed a change so unpackAttributes now returns an error for a malformed attribute instead of skipping it:
- Search returns the error to the caller; SearchAsync delivers it on the result channel as SearchSingleResult.Error.
- Applied the same treatment to the per-value assertion, so a non-string value also reports an error rather than silently decoding as an empty string.
- Updated the test to expect errors for the missing-vals and non-string-type cases; go build, go vet and the unit tests pass locally.
| } | ||
| name, ok := child.Children[0].Value.(string) | ||
| if !ok { | ||
| continue |
Contributor
Author
There was a problem hiding this comment.
Done here as well, this path returns an error now too.
Contributor
Author
|
gentle ping |
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.
Return an error for an attribute that lacks the two expected children or whose type or value is not a string, so the caller can handle it: Search returns it to the caller, SearchAsync delivers it on the result channel as SearchSingleResult.Error. Well-formed entries decode exactly as before. Added a unit test covering the missing-vals and non-string-type cases.