Skip to content

Commit d82ad41

Browse files
committed
Use aligned control buffers and CMSG macros for ancillary data
pack_ancillary_messages wrote cmsghdr fields through CMSG_FIRSTHDR and CMSG_NXTHDR pointers into a Vec<u8>, which has byte alignment. Receive storage was aligned only to cmsghdr and parsed by a hand-written walker emulating per-platform CMSG_NXTHDR behavior; AF_ALG computed header offsets by hand. - Add ControlBuffer, zero-initialized msg_control storage aligned to 16 bytes, used by sendmsg, recvmsg/recvmsg_into and sendmsg_afalg. - sendmsg: limit the control length to SOCKLEN_T_LIMIT, walk headers with CMSG_FIRSTHDR/CMSG_NXTHDR, check them with cmsg_min_space and get_cmsg_data_space, and raise the matching RuntimeErrors. Align the argument and ancillary item error messages with sock_sendmsg. - recvmsg/recvmsg_into: walk the received msghdr with the CMSG macros and get_cmsg_data_len, report truncated or malformed control data as AncillaryDataStatus, emit the RuntimeWarning for it, and close received SCM_RIGHTS descriptors when building the result fails. Validate ancbufsize against SOCKLEN_T_LIMIT. - sendmsg_afalg: build the control buffer with the CMSG macros and validate family, op and assoclen with the same errors as sock_sendmsg_afalg; remove the unused host sendmsg_afalg. - Replace the old parser tests with tests for packing, parsing, truncation, malformed headers, an SCM_RIGHTS round trip and the AF_ALG header layout. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7
1 parent 2933db2 commit d82ad41

3 files changed

Lines changed: 758 additions & 409 deletions

File tree

0 commit comments

Comments
 (0)