Skip to content

nil dereference panics prevention#566

Open
artemseleznev wants to merge 4 commits intogo-ldap:masterfrom
Infowatch:master
Open

nil dereference panics prevention#566
artemseleznev wants to merge 4 commits intogo-ldap:masterfrom
Infowatch:master

Conversation

@artemseleznev
Copy link
Copy Markdown
Contributor

Hi! I should've fix other branches in my previous PR, but better late than never :)

@artemseleznev artemseleznev marked this pull request as ready for review September 19, 2025 09:47

func NewControlServerSideSorting(value *ber.Packet) (*ControlServerSideSorting, error) {
if value == nil || len(value.Children) < 2 {
return new(ControlServerSideSorting), nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would satisfy your scanner, but would result in a faulty message due to the controlValue not having the necesarry fields for encoding the message.

ldap/v3/control.go

Lines 948 to 979 in 82fef14

func (c *ControlServerSideSorting) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
control := ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, c.GetControlType(), "Control Type")
value := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value")
seqs := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "SortKeyList")
for _, f := range c.SortKeys {
seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "")
seq.AppendChild(
ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, f.AttributeType, "attributeType"),
)
seq.AppendChild(
ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, f.MatchingRule, "orderingRule"),
)
if f.Reverse {
seq.AppendChild(
ber.NewBoolean(ber.ClassContext, ber.TypePrimitive, 1, f.Reverse, "reverseOrder"),
)
}
seqs.AppendChild(seq)
}
value.AppendChild(seqs)
packet.AppendChild(control)
packet.AppendChild(value)
return packet
}

I suggest to disregard this particular change. The function is never called from a message processor but only by a developer.

Copy link
Copy Markdown
Contributor Author

@artemseleznev artemseleznev Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpuschma thank you for your feedback!
Yes, I fix this because the scanner marked this code, but I also prefer not to get panics in my project:-)

Please let me know if my fixes are excess, or some of them (not only in NewControlServerSideSorting)

@cpuschma cpuschma self-assigned this Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants