From 8823e2b064c2e71a3b93f1086dc39c6a50b44a29 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 15 Nov 2016 12:10:50 +0100 Subject: [PATCH] ntp: ignore truncated messages Don't waste time with processing messages that don't fit in the receive buffer as they most likely wouldn't pass the format check due to an invalid length of an extension field. --- ntp_io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ntp_io.c b/ntp_io.c index 7660eb6..6703321 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -598,6 +598,12 @@ process_message(struct msghdr *hdr, int length, int sock_fd) local_addr.sock_fd = sock_fd; if_index = -1; + if (hdr->msg_flags & MSG_TRUNC) { + DEBUG_LOG(LOGF_NtpIO, "Received truncated message from %s:%d", + UTI_IPToString(&remote_addr.ip_addr), remote_addr.port); + return; + } + for (cmsg = CMSG_FIRSTHDR(hdr); cmsg; cmsg = CMSG_NXTHDR(hdr, cmsg)) { #ifdef HAVE_IN_PKTINFO if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) {