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

trafgen: Fix for ipv6 header generation when L3-only devices are present #233

Conversation

MatPerin
Copy link
Contributor

When trying to run trafgen with a config which included the ipv6() header generation helper function, I noticed the tool halting without sending any traffic.

By further inspection I found out that the issue was a segmentation fault caused by NULL pointer deferencing inside the lookup function for the device ipv6 address.
Apparently, the getifaddrs function returns a linked list node for L2 even in the case of L3 interfaces (in my case, it was a TUN device created in the network) but with the pointer to the address structure set to NULL. This causes a segfault when trying to access the address family from it.
I solved the issue by checking the validity of the pointer beforehand.

Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @MatPerin!

One small nit inline. Also, could you please add the change description to the commit message as well and add a Signed-off-by line as outlined in SubmittingPatches?

dev.c Outdated Show resolved Hide resolved
@MatPerin MatPerin force-pushed the trafgen_ipv6_device_address_lookup_segfault_fix branch from 1ff31b8 to f80bbf4 Compare April 22, 2022 08:47
The getifaddrs function returns a linked list node for L2
even in the case of L3 interfaces (e.g. a TUN device), but
with the pointer to the address structure set to NULL.
This causes a segfault when trying to access the address
family from it when such network interfaces are present
in the system.

The issue is solved by checking the validity of the pointer
beforehand: if the address structure is present the address
family can be fetched and the current iteration can go on
safely, otherwise the node is skipped (as it is not linked
to any address).

Signed-off-by: Matteo Perin <[email protected]>
@MatPerin MatPerin force-pushed the trafgen_ipv6_device_address_lookup_segfault_fix branch from f80bbf4 to 8c4040c Compare April 22, 2022 09:00
@MatPerin
Copy link
Contributor Author

Sure, sorry for not including the commit message and the signed-off-by label.
It should be all fixed now, let me know if further changes are needed.

@MatPerin MatPerin requested a review from tklauser April 22, 2022 09:10
Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Thank you @MatPerin, looks perfect now!

@tklauser tklauser merged commit b23c151 into netsniff-ng:master Apr 22, 2022
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.

None yet

2 participants