Skip to content

Zero-initialize sockaddr_storage in inet_parse()#10

Merged
troglobit merged 1 commit intotroglobit:masterfrom
dangowrt:zero-initialize-sockaddr_storage-in-inet_parse
Mar 21, 2026
Merged

Zero-initialize sockaddr_storage in inet_parse()#10
troglobit merged 1 commit intotroglobit:masterfrom
dangowrt:zero-initialize-sockaddr_storage-in-inet_parse

Conversation

@dangowrt
Copy link
Copy Markdown
Contributor

inet_parse() only sets sin6_family, sin6_addr, and sin6_port, leaving sin6_scope_id and sin6_flowinfo uninitialized. When the caller's inet_addr_t is on the stack, these fields contain garbage which the kernel may interpret — e.g., a non-zero sin6_scope_id causes bind() to fail with ENODEV when the garbage value doesn't match any interface index.

Zero the entire struct before populating it.

inet_parse() only sets sin6_family, sin6_addr, and sin6_port, leaving
sin6_scope_id and sin6_flowinfo uninitialized. When the caller's
inet_addr_t is on the stack, these fields contain garbage which the
kernel may interpret - e.g., a non-zero sin6_scope_id causes bind() to
fail with ENODEV when the garbage value doesn't match any interface
index.

Zero the entire struct before populating it.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@dangowrt dangowrt force-pushed the zero-initialize-sockaddr_storage-in-inet_parse branch from 7f16b6b to 96de688 Compare March 21, 2026 14:48
@troglobit troglobit merged commit a1f010f into troglobit:master Mar 21, 2026
@dangowrt dangowrt deleted the zero-initialize-sockaddr_storage-in-inet_parse branch March 21, 2026 19:02
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