Skip to content

Fix null dereference and iface overrun in getifaddrs path#158

Open
andy5995 wants to merge 1 commit intolibsdl-org:mainfrom
andy5995:fix-getifaddrs-null-deref
Open

Fix null dereference and iface overrun in getifaddrs path#158
andy5995 wants to merge 1 commit intolibsdl-org:mainfrom
andy5995:fix-getifaddrs-null-deref

Conversation

@andy5995
Copy link
Copy Markdown
Contributor

Here's what @claude found. Looks ok to me...

POSIX allows ifa_addr to be NULL (e.g. interfaces with no assigned address). Add an explicit NULL check and skip such entries, adjusting new_num_interfaces since they were counted in the first pass.

The loop also had iface++ in the for-header, so any continue — including the ifa_name == NULL early-out — would still advance the pointer past an unfilled slot. Since NULL-named entries were not counted in the sizing pass, this caused subsequent slot writes to go out of bounds. Fix by moving iface++ to the bottom of the loop body so it only fires when a slot is actually filled, and remove the now-unnecessary iface-- that was compensating for the old premature increment.

POSIX allows ifa_addr to be NULL (e.g. interfaces with no assigned
address). Add an explicit NULL check and skip such entries, adjusting
new_num_interfaces since they were counted in the first pass.

The loop also had iface++ in the for-header, so any continue — including
the ifa_name == NULL early-out — would still advance the pointer past an
unfilled slot. Since NULL-named entries were not counted in the sizing
pass, this caused subsequent slot writes to go out of bounds. Fix by
moving iface++ to the bottom of the loop body so it only fires when a
slot is actually filled, and remove the now-unnecessary iface-- that was
compensating for the old premature increment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant