Skip to content

Commit f391df3

Browse files
gibbz00tgross35
authored andcommitted
Properly set cmsg_len in CMSG_NXTHDR tests.
Setting `(*pcmsghdr).cmsg_len = cmsg_len as _;` when cmsg_len ranges from 0 to 64 is invalid as it must always be `>= size_of::<cmsghdr>()`, rounded up to the nearest alignment boundary. Some implementations (notably glbic) do check that `cmsg_len >= size_of::<cmsghdr>()` in `CMSG_NXTHDR`, returning null if so. But this is more so an extra precaution that is not mentioned in the POSIX 1003.1-2024. It can therefore not be relied on for tests executed on multiple platforms. The change also removes the ignoring of some testvalues when targeting AIX.
1 parent 1e43edb commit f391df3

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

libc-test/tests/cmsg.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,10 @@ mod t {
7474
let pcmsghdr = buffer.0.as_mut_ptr().cast::<cmsghdr>();
7575
mhdr.msg_control = pcmsghdr.cast::<c_void>();
7676
mhdr.msg_controllen = (160 - start_ofs) as _;
77-
for cmsg_len in 0..64 {
78-
// Address must be a multiple of 0x4 for testing on AIX.
79-
if cfg!(target_os = "aix") && cmsg_len % std::mem::size_of::<cmsghdr>() != 0 {
80-
continue;
81-
}
77+
for cmsg_payload_len in 0..64 {
8278
unsafe {
8379
pcmsghdr.cast::<u8>().write_bytes(0, CAPACITY);
84-
(*pcmsghdr).cmsg_len = cmsg_len as _;
80+
(*pcmsghdr).cmsg_len = libc::CMSG_LEN(cmsg_payload_len as _) as _;
8581
let libc_next = libc::CMSG_NXTHDR(&mhdr, pcmsghdr);
8682
let next = cmsg_nxthdr(&mhdr, pcmsghdr);
8783
assert_eq!(libc_next, next);

0 commit comments

Comments
 (0)