Skip to content

Conversation

aroulin
Copy link
Contributor

@aroulin aroulin commented Nov 23, 2022

The current code has a hardcoded limit of 512 IP addresses. The static array will be overflowed when more addresses are present.

Fix the static limit by using realloc when the array needs to grow to accomodate more interfaces.

I verified on a setup with 1200+ interfaces/IPs and also ran valgrind to confirm there's no memory leak.

Closes: #149

@troglobit troglobit self-requested a review November 23, 2022 07:18
@troglobit
Copy link
Collaborator

Thanks for submitting this PR! Please update it with my comments and rebase+squash that.

The current code has a hardcoded limit of 512 IP addresses.
The static array will be overflowed when more addresses are
present.

Fix the static limit by using realloc when the array needs to grow
to accomodate more interfaces.

Growing the array by a factor of 1.5 each time (close to golden ratio)
to maximize reuse of previously allocated space.
@aroulin aroulin force-pushed the fix-segfault-ifaddrlist branch from b677cfd to 8b4688c Compare November 23, 2022 17:32
@troglobit
Copy link
Collaborator

Looks awesome, great work! Unleashing CI, when it completes I'll merge :-)

@troglobit troglobit merged commit b5e2af2 into libnet:master Nov 23, 2022
troglobit added a commit that referenced this pull request Dec 28, 2022
libnet has multiple libnet_ifaddrlist(), one for each OS family.  The
changes in PR #150, fixing the aribtrary MAX IP address limit on LInux,
unfortunately broke all other operating systems.

This change is for the "other" operating system that are not Windows.
Tested on macOS.

Issue #150

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
troglobit added a commit that referenced this pull request Dec 28, 2022
libnet has multiple libnet_ifaddrlist(), one for each OS family.  The
changes in PR #150, fixing the aribtrary MAX IP address limit on LInux,
unfortunately broke all other operating systems.

This is a specualtive change for the Windows operating system, untested.

Issue #150

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
@troglobit
Copy link
Collaborator

Unfortunately this PR caused a few regressions. I dusted off my old MacBook Pro to figure out was going on. Commits f7f0a11 (macOS and "other" OSs) and 2bc784f should fix the regression, although the fix for Windows has not been tested due to lack of a Windows machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault in libnet_ifaddrlist
2 participants