ntp: check value returned by CMSG_FIRSTHDR
In NIO_Linux_RequestTxTimestamp(), check the returned pointer and the length of the buffer before adding the control message. This fixes an issue reported by the Clang static analyzer.
This commit is contained in:
parent
69d3913f3e
commit
64fd1b8ba5
1 changed files with 6 additions and 1 deletions
|
@ -856,7 +856,12 @@ NIO_Linux_RequestTxTimestamp(struct msghdr *msg, int cmsglen, int sock_fd)
|
||||||
/* Add control message that will enable TX timestamping for this message.
|
/* Add control message that will enable TX timestamping for this message.
|
||||||
Don't use CMSG_NXTHDR as the one in glibc is buggy for creating new
|
Don't use CMSG_NXTHDR as the one in glibc is buggy for creating new
|
||||||
control messages. */
|
control messages. */
|
||||||
cmsg = (struct cmsghdr *)((char *)CMSG_FIRSTHDR(msg) + cmsglen);
|
|
||||||
|
cmsg = CMSG_FIRSTHDR(msg);
|
||||||
|
if (!cmsg || cmsglen + CMSG_SPACE(sizeof (ts_tx_flags)) > msg->msg_controllen)
|
||||||
|
return cmsglen;
|
||||||
|
|
||||||
|
cmsg = (struct cmsghdr *)((char *)cmsg + cmsglen);
|
||||||
memset(cmsg, 0, CMSG_SPACE(sizeof (ts_tx_flags)));
|
memset(cmsg, 0, CMSG_SPACE(sizeof (ts_tx_flags)));
|
||||||
cmsglen += CMSG_SPACE(sizeof (ts_tx_flags));
|
cmsglen += CMSG_SPACE(sizeof (ts_tx_flags));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue