From: Peter van Dijk Date: Fri, 13 Feb 2015 08:29:00 +0000 (+0100) Subject: make sure we never call sendmsg with msg_control!=NULL && msg_controllen>0. Fixes... X-Git-Tag: dnsdist-1.0.0-alpha1~306^2~13^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=579cae1903744afc2f411bcfdb3101f699208d2d;p=pdns make sure we never call sendmsg with msg_control!=NULL && msg_controllen>0. Fixes #2227 --- diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 83c48d9ca..5ea22f979 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -115,6 +115,7 @@ bool IsAnyAddress(const ComboAddress& addr) return false; } +// FIXME: this function is unused, and using it could reduce some code duplication int sendfromto(int sock, const char* data, int len, int flags, const ComboAddress& from, const ComboAddress& to) { struct msghdr msgh; @@ -133,11 +134,15 @@ int sendfromto(int sock, const char* data, int len, int flags, const ComboAddres if(from.sin4.sin_family) { addCMsgSrcAddr(&msgh, cbuf, &from); } + else { + msgh.msg_control=NULL; + } return sendmsg(sock, &msgh, flags); } // be careful: when using this for receive purposes, make sure addr->sin4.sin_family is set appropriately so getSocklen works! // be careful: when using this function for *send* purposes, be sure to set cbufsize to 0! +// be careful: if you don't call addCMsgSrcAddr after fillMSGHdr, make sure to set msg_control to NULL void fillMSGHdr(struct msghdr* msgh, struct iovec* iov, char* cbuf, size_t cbufsize, char* data, size_t datalen, ComboAddress* addr) { iov->iov_base = data; diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 99be86b99..27823af82 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -300,6 +300,9 @@ void UDPNameserver::send(DNSPacket *p) if(p->d_anyLocal) { addCMsgSrcAddr(&msgh, cbuf, p->d_anyLocal.get_ptr()); } + else { + msgh.msg_control=NULL; + } DLOG(L<getRemote() <<" ("<< buffer.length()<<" octets)"< p->getMaxReplyLen()) { L< "<getMaxReplyLen()<d_remote); if(dc->d_local.sin4.sin_family) addCMsgSrcAddr(&msgh, cbuf, &dc->d_local); + else + msgh.msg_control=NULL; sendmsg(dc->d_socket, &msgh, 0); if(!SyncRes::s_nopacketcache && !variableAnswer ) { t_packetCache->insertResponsePacket(string((const char*)&*packet.begin(), packet.size()), @@ -961,6 +963,9 @@ string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fr if(destaddr.sin4.sin_family) { addCMsgSrcAddr(&msgh, cbuf, &destaddr); } + else { + msgh.msg_control=NULL; + } sendmsg(fd, &msgh, 0); if(response.length() >= sizeof(struct dnsheader)) {