Permalink
Browse files

make sure we never call sendmsg with msg_control!=NULL && msg_control…

…len>0. Fixes #2227
  • Loading branch information...
1 parent d63f0d8 commit a7be3f1214bd5c8304fa866c28086c28d5b78a39 @Habbie Habbie committed Feb 13, 2015
Showing with 13 additions and 0 deletions.
  1. +5 −0 pdns/iputils.cc
  2. +3 −0 pdns/nameserver.cc
  3. +5 −0 pdns/pdns_recursor.cc
View
@@ -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;
View
@@ -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<<Logger::Notice<<"Sending a packet to "<< p->getRemote() <<" ("<< buffer.length()<<" octets)"<<endl);
if(buffer.length() > p->getMaxReplyLen()) {
L<<Logger::Error<<"Weird, trying to send a message that needs truncation, "<< buffer.length()<<" > "<<p->getMaxReplyLen()<<endl;
@@ -688,6 +688,8 @@ void startDoResolve(void *p)
fillMSGHdr(&msgh, &iov, cbuf, 0, (char*)&*packet.begin(), packet.size(), &dc->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)) {

0 comments on commit a7be3f1

Please sign in to comment.