-
Notifications
You must be signed in to change notification settings - Fork 369
nil dereference panics prevention #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
||
func NewControlServerSideSorting(value *ber.Packet) (*ControlServerSideSorting, error) { | ||
if value == nil || len(value.Children) < 2 { | ||
return new(ControlServerSideSorting), nil |
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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
)
Hi! I should've fix other branches in my previous PR, but better late than never :)