Re: [PATCH] linux: align the ancillary buffer in tst-socket-timestamp
Florian Weimer <[email protected]>
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <[email protected]> |
* Matt Turner:
> size_t msg_controllen = CMSG_SPACE (tsize) + slack;
> - char *msg_control = cmsg - msg_controllen;
> + /* The buffer has to be suitably aligned for struct cmsghdr, since both
> + recvmsg and the CMSG_* macros below read cmsg_len from its start, so
> + round the start down. A slack that is not a multiple of the alignment
> + then leaves the buffer ending just short of the guard page rather than
> + against it, which still catches the overruns this is looking for: they
> + are a whole timestamp, not a few bytes. */
> + char *msg_control = PTR_ALIGN_DOWN ((char *) cmsg - msg_controllen,
> + __alignof__ (struct cmsghdr));
> memset (msg_control, 0x55, msg_controllen);
> struct mmsghdr mmhdr =
> {
I think it's more obviously correct if you add the alignment (minus 1)
to the requested allocation size. It probably won't make difference in
practice (page sizes are large enough).
Thanks,
Florian