From 7f81854251215620101fac684793d8aa2ab9ffd2 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 1 Jul 2019 10:00:35 +0200 Subject: [PATCH] Add static assertions for the size of the src address control buffer --- pdns/misc.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pdns/misc.cc b/pdns/misc.cc index 2686b0fc46..6626702771 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -893,6 +893,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in6_pktinfo *pkt; msgh->msg_control = cmsgbuf; + static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in6_pktinfo"); msgh->msg_controllen = CMSG_SPACE(sizeof(*pkt)); cmsg = CMSG_FIRSTHDR(msgh); @@ -910,6 +911,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in_pktinfo *pkt; msgh->msg_control = cmsgbuf; + static_assert(CMSG_SPACE(sizeof(*pkt)) <= sizeof(*cmsgbuf), "Buffer is too small for in_pktinfo"); msgh->msg_controllen = CMSG_SPACE(sizeof(*pkt)); cmsg = CMSG_FIRSTHDR(msgh); @@ -925,6 +927,7 @@ void addCMsgSrcAddr(struct msghdr* msgh, cmsgbuf_aligned* cmsgbuf, const ComboAd struct in_addr *in; msgh->msg_control = cmsgbuf; + static_assert(CMSG_SPACE(sizeof(*in)) <= sizeof(*cmsgbuf), "Buffer is too small for in_addr"); msgh->msg_controllen = CMSG_SPACE(sizeof(*in)); cmsg = CMSG_FIRSTHDR(msgh); -- 2.47.2