Skip to content

Commit

Permalink
Merge pull request #13019 from rgacogne/fix-calidns-issues
Browse files Browse the repository at this point in the history
calidns: Prevent a crash on an empty domains file
  • Loading branch information
rgacogne authored Jul 31, 2023
2 parents 360bc53 + f78d203 commit e826d58
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pdns/calidns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ static po::variables_map g_vm;

static bool g_quiet;

static void* recvThread(const vector<std::unique_ptr<Socket>>* sockets)
//NOLINTNEXTLINE(performance-unnecessary-value-param): we do want a copy to increase the reference count, thank you very much
static void recvThread(const std::shared_ptr<std::vector<std::unique_ptr<Socket>>> sockets)
{
vector<pollfd> rfds, fds;
for(const auto& s : *sockets) {
for (const auto& s : *sockets) {
if (s == nullptr) {
continue;
}
struct pollfd pfd;
pfd.fd = s->getHandle();
pfd.events = POLLIN;
Expand Down Expand Up @@ -114,7 +118,6 @@ static void* recvThread(const vector<std::unique_ptr<Socket>>* sockets)
}
}
}
return 0;
}

static ComboAddress getRandomAddressFromRange(const Netmask& ecsRange)
Expand All @@ -140,7 +143,7 @@ static void replaceEDNSClientSubnet(vector<uint8_t>* packet, const Netmask& ecsR
memcpy(&packet->at(packetSize - sizeof(addr)), &addr, sizeof(addr));
}

static void sendPackets(const vector<std::unique_ptr<Socket>>& sockets, const vector<vector<uint8_t>* >& packets, int qps, ComboAddress dest, const Netmask& ecsRange)
static void sendPackets(const vector<std::unique_ptr<Socket>>& sockets, const vector<vector<uint8_t>* >& packets, uint32_t qps, ComboAddress dest, const Netmask& ecsRange)
{
unsigned int burst=100;
const auto nsecPerBurst=1*(unsigned long)(burst*1000000000.0/qps);
Expand Down Expand Up @@ -383,7 +386,7 @@ try
cout<<"Generated "<<unknown.size()<<" ready to use queries"<<endl;
}

vector<std::unique_ptr<Socket>> sockets;
auto sockets = std::make_shared<std::vector<std::unique_ptr<Socket>>>();
ComboAddress dest;
try {
dest = ComboAddress(g_vm["destination"].as<string>(), 53);
Expand Down Expand Up @@ -412,9 +415,14 @@ try
}
}

sockets.push_back(std::move(sock));
sockets->push_back(std::move(sock));
}
new thread(recvThread, &sockets);

{
std::thread receiver(recvThread, sockets);
receiver.detach();
}

uint32_t qps;

ofstream plot;
Expand Down Expand Up @@ -465,7 +473,7 @@ try
DTime dt;
dt.set();

sendPackets(sockets, toSend, qps, dest, ecsRange);
sendPackets(*sockets, toSend, qps, dest, ecsRange);

const auto udiff = dt.udiffNoReset();
const auto realqps=toSend.size()/(udiff/1000000.0);
Expand Down

0 comments on commit e826d58

Please sign in to comment.