[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Misleading example code in CMSG_DATA(3) manpage
- To: bugs_(_at_)_OpenBSD_(_dot_)_org
- Subject: Re: Misleading example code in CMSG_DATA(3) manpage
- From: Christian Biere <christianbiere_(_at_)_gmx_(_dot_)_de>
- Date: Sun, 19 Feb 2006 22:47:34 +0100
- Openpgp: id=7A3220C7; url=http://ghostwhitecrab.com/cbiere.pgp
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
Visit your host, monkey.org