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 alignment problem when casting struct sockaddr pointers to SockAddr. #26488

Conversation

bzbarsky-apple
Copy link
Contributor

SockAddr, because it includes sockaddr_storage, has a more stringent alignment requirement than struct sockaddr does. As a result, the casting we do of "sockaddr &" to "SockAddr &" is not really OK.

The fix is to have a version of SockAddr that lets us do the type-punning we want to do without including sockaddr_storage. We don't need storage in this case because we are working with an existing sockaddr that lives somewhere, not storing one of our own.

This also lets us enable UndefinedBehaviorSanitizer for libCHIP in the Darwin framework tests.

SockAddr, because it includes sockaddr_storage, has a more stringent alignment
requirement than struct sockaddr does.  As a result, the casting we do of
"sockaddr &" to "SockAddr &" is not really OK.

The fix is to have a version of SockAddr that lets us do the type-punning we
want to do without including sockaddr_storage.  We don't need storage in this
case because we are working with an existing sockaddr that lives somewhere, not
storing one of our own.

This also lets us enable UndefinedBehaviorSanitizer for libCHIP in the Darwin
framework tests.
@bzbarsky-apple bzbarsky-apple force-pushed the fix-SockAddr-alignment-problem branch from 92f0839 to 5b6ab70 Compare May 11, 2023 00:27
src/inet/IPAddress.h Outdated Show resolved Hide resolved
src/inet/IPAddress.h Outdated Show resolved Hide resolved
@bzbarsky-apple bzbarsky-apple merged commit a3b4005 into project-chip:master May 12, 2023
@bzbarsky-apple bzbarsky-apple deleted the fix-SockAddr-alignment-problem branch May 12, 2023 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants