interprocess
interprocess copied to clipboard
Element offset does not follow global offset resulting in wrong read for second and after items in the array
If you look closely when you read both the right and credentials here https://github.com/kotauskas/interprocess/blob/master/src/os/unix/udsocket/ancillary.rs#L348 and here https://github.com/kotauskas/interprocess/blob/master/src/os/unix/udsocket/ancillary.rs#L359-L364 you are only reading by using the element_offset, however that offset is always equal to 12 or 16 https://github.com/kotauskas/interprocess/blob/master/src/os/unix/udsocket/ancillary.rs#L330
// The cmsg_level field is always SOL_SOCKET — we don't need it, let's get the
// cmsg_type field right away by first getting the offset at which it's
// located:
#[cfg(target_pointer_width = "64")]
let type_offset: usize = 8 + 4; // 8 for cmsg_size, 4 for cmsg_level
#[cfg(target_pointer_width = "32")]
let type_offset: usize = 4 + 4; // 4 for cmsg_size, 4 for cmsg_level
// Now let's get the type itself:
let element_type = u32_from_slice(&bytes[self.i + type_offset..=self.i + type_offset + 4]);
// The size of cmsg_size, cmsg_level and cmsg_type together
let element_offset = type_offset + 4;
This is fine for the first element of an array however this will not be for the second element of that array, thus you need to add self.i which is the global offset to it fix is as simple as that:
let element_offset = self.i + type_offset + 4;
Commit for reference : https://github.com/ETKNeil/interprocess/commit/0c1e66c91cc670696e786e5d5cbd185ea8d0cb51