Skip to content

Length check in *_SetVendor causes a panic in generated vendor dictionaries #121

Description

@maddsua

Device: Juniper MX80
Dictionary: https://fossies.org/linux/freeradius-server/share/dictionary.erx
Error: runtime error: slice bounds out of range [34:0]
Failing generated function: ERXServiceActivate_Set

Code line in question:

p(w, ` for j := 0; len(vsa[j:]) >= 3; {`)

Proposed solution: replace that slicing and length check with just subtraction like this:

-               for j := 0; len(vsa[j:]) >= 3; {
+               for j := 0; len(vsa)-j >= 3; {
                        vsaTyp, vsaLen := vsa[0], vsa[1]
-                       if int(vsaLen) > len(vsa[j:]) || vsaLen < 3 {
+                       if int(vsaLen) > len(vsa)-j || vsaLen < 3 {
                                i++
                                break
                        }

Let me know if I'm missing something, but I think this should work just fine. I don't really understand the reason for slicing a slice first and then checking it's length, when you can subtract index from original length and get the same result but without a risk of painc.

UPD: just noticed the same pattern in *_DelVendor. I think that it should be replaced as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions