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

Fix ParseMACAddressFields #135

Merged
merged 1 commit into from
Dec 2, 2023

Conversation

mercimat
Copy link
Contributor

@mercimat mercimat commented Nov 22, 2023

When using ParseMACAddressFields to parse a MACAddress IE, only the Flags field is correctly initialized. All the source/destination/uppersource/upperdestination mac address fields remain empty.

After investigation, it appears that when using copy, the number of elements copied is the the minimum of len(src) and len(dst) - see doc here.
But at this point, the MAC address fields are nil. So the copy didn't update the MAC address fields.

The fix proposal here is to initialize each field as a net.HardwareAddr of size 6. net.HardwareAddr being a type alias for []byte, the MAC address field will have the correct size to be able to copy the content of b[offset:offset+6] into it.

I also added unit tests to cover this issue, plus extra test cases around the ParseMACAddressFields.
I'm not sure about the convention to follow here. The existing unit tests files seemed to cover generic parsing of IEs. But as this is more a specific parsing function, I opted for putting them under ie/mac_address_test.go.
Please let me know In case the unit tests should be moved somewhere else.

I also ran all the unit tests locally to verify that they still passed with my changes.

Copy link
Owner

@wmnsk wmnsk left a comment

Choose a reason for hiding this comment

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

Great catch, thanks a lot!

@wmnsk wmnsk merged commit 030dc55 into wmnsk:master Dec 2, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants