Ticket #96: serial-increment-fix.patch

File serial-increment-fix.patch, 1.6 KB (added by ondrej@…, 7 years ago)

First patch - not tested yet

  • pdns/packethandler.cc

    diff -urN pdns-2.9.20.orig/pdns/packethandler.cc pdns-2.9.20/pdns/packethandler.cc
    old new  
    479479  return RCode::NoError; 
    480480} 
    481481 
     482#define SERIAL_WRAP 4294967296 
     483#define SERIAL_MAX_INCREMENT 2147483648 
     484 
    482485int PacketHandler::processNotify(DNSPacket *p) 
    483486{ 
    484487  /* now what?  
     
    504507  } 
    505508 
    506509  uint32_t theirserial=0; 
     510  uint64_t increment=0; 
    507511 
    508512  /* to quote Rusty Russell - this code is so bad that you can actually hear it suck */ 
    509513  /* this is an instant DoS, just spoof notifications from the address of the master and we block  */ 
     
    514518    L<<Logger::Error<<"Unable to determine SOA serial for "<<p->qdomain<<" at "<<p->getRemote()<<endl; 
    515519    return RCode::ServFail; 
    516520  } 
    517          
    518521 
    519   if(theirserial<=di.serial) { 
     522  if (theirserial<=di.serial) { 
     523    increment = SERIAL_WRAP; 
     524  } 
     525  increment += theirserial - di.serial; 
     526 
     527  if(increment<0) { 
    520528    L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from master "<<p->getRemote()<<", we are up to date: "<< 
    521529      theirserial<<"<="<<di.serial<<endl; 
    522530    return RCode::NoError; 
    523531  } 
     532  else if (increment>SERIAL_MAX_INCREMENT) { 
     533    L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from master "<<p->getRemote()<<", increment too big: "<< 
     534      increment<<">"<<MAX_SERIAL_INCREMENT<<endl; 
     535    return RCode::NoError; 
     536  }    
    524537  else { 
    525538    L<<Logger::Error<<"Received valid NOTIFY for "<<p->qdomain<<" (id="<<di.id<<") from master "<<p->getRemote()<<": "<< 
    526539      theirserial<<" > "<<di.serial<<endl;