Skip to content
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

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

Open
maddsua opened this issue Jun 16, 2024 · 1 comment · May be fixed by #125
Open

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

maddsua opened this issue Jun 16, 2024 · 1 comment · May be fixed by #125

Comments

@maddsua
Copy link

maddsua commented Jun 16, 2024

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

@maddsua
Copy link
Author

maddsua commented Aug 14, 2024

forking and making a PR, as having to monkey-patch this in the actual project seems like a huge delayed footgun

@maddsua maddsua linked a pull request Aug 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant