Skip to content

Commit

Permalink
rec: Treat requestor's payload size lower than 512 as equal to 512
Browse files Browse the repository at this point in the history
(cherry picked from commit 3201574)
  • Loading branch information
rgacogne committed Jun 22, 2017
1 parent ff2a5c0 commit a5c9534
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pdns/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,16 @@ void startDoResolve(void *p)
if (t_queryring)
t_queryring->push_back(make_pair(dc->d_mdp.d_qname, dc->d_mdp.d_qtype));

uint32_t maxanswersize= dc->d_tcp ? 65535 : min((uint16_t) 512, g_udpTruncationThreshold);
uint16_t maxanswersize = dc->d_tcp ? 65535 : min(static_cast<uint16_t>(512), g_udpTruncationThreshold);
EDNSOpts edo;
bool haveEDNS=false;
if(getEDNSOpts(dc->d_mdp, &edo)) {
if(!dc->d_tcp)
maxanswersize = min(edo.d_packetsize, g_udpTruncationThreshold);
if(!dc->d_tcp) {
/* rfc6891 6.2.3:
"Values lower than 512 MUST be treated as equal to 512."
*/
maxanswersize = min(static_cast<uint16_t>(edo.d_packetsize >= 512 ? edo.d_packetsize : 512), g_udpTruncationThreshold);
}
dc->d_ednsOpts = edo.d_options;
haveEDNS=true;

Expand Down Expand Up @@ -1086,7 +1090,7 @@ void startDoResolve(void *p)
if(i->d_type != QType::OPT) // their TTL ain't real
minTTL = min(minTTL, i->d_ttl);
i->d_content->toPacket(pw);
if(pw.size() > maxanswersize) {
if(pw.size() > static_cast<size_t>(maxanswersize)) {
pw.rollback();
if(i->d_place==DNSResourceRecord::ANSWER) // only truncate if we actually omitted parts of the answer
{
Expand Down

0 comments on commit a5c9534

Please sign in to comment.