On Wed, Jan 01, 2025 at 08:07:04PM +0000, Diego Nieto Cid wrote:
> On Wed, Jan 01, 2025 at 06:51:47PM +0100, Samuel Thibault wrote:
> > > 
> > >     /* Structure used for storage of ancillary data object information.  
> > > */
> > >     struct cmsghdr
> > >       {
> > >         socklen_t cmsg_len;         /* Length of data in cmsg_data plus 
> > > length
> > >                                        of cmsghdr structure.  */
> > 
> > That's the correct type according to posix:
> > 
> > ./basedefs/sys_socket.h.html:<tt>socklen_t  cmsg_len   </tt> Data byte 
> > count, including the <b>cmsghdr</b>. <tt>
> >
> 
> Ok, but we are giving unaligned data pointers with the current implementation
> of CMSG_DATA.
>

On the other hand, nothing says the pointer shall be aligned:

    CMSG_DATA(cmsg) [1]

    If the argument is a pointer to a cmsghdr structure, this macro
    shall return an unsigned character pointer to the data array
    associated with the cmsghdr structure.


[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html

and GLib computation is relying on undefined behaviour.

Reply via email to