[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Misleading example code in CMSG_DATA(3) manpage



Christian Biere wrote:
> Okay, there's something I missed. As long as you don't provide more
> cmsg buffer than CMSG_SPACE(sizeof (int)) - and the example code
> uses this - the kernel will release file descriptors that don't
> fit into this buffer. Therefore, I think this PR can be closed.

There are still two issues:

1. msg.msg_controllen should be set to CMSG_LEN(sizeof(int)) not
   sizeof(buf).
2. The (int *) cast is bad because there's no guarantee that the
   buffer is properly aligned as it's an array of unsigned char. This
   matters on architectures with strict alignment requirements.

-- 
Christian