From: Bert Hubert Date: Thu, 6 Jan 2011 13:03:50 +0000 (+0000) Subject: spotted by Wouter Wijngaards, turns out we were incrementing/decrementing already... X-Git-Tag: auth-3.0~434 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c3e047da030f2f1c371f6f650f833ff78de54f6;p=pdns spotted by Wouter Wijngaards, turns out we were incrementing/decrementing already base32hex encoded hashes, which works only sometimes ;-) git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1813 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index d95daa68e..3570ffe0b 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -541,32 +541,38 @@ void PacketHandler::addNSECX(DNSPacket *p, DNSPacket *r, const string& target, c } } +//we juggle raw & base32 encoded hashes too much static void incrementHash(std::string& hash) // I wonder if this is correct, cmouse? ;-) { if(hash.empty()) return; - for(string::size_type pos=hash.size(); pos; ) { + string raw=fromBase32Hex(hash); + for(string::size_type pos=raw.size(); pos; ) { --pos; - unsigned char c = (unsigned char)hash[pos]; + unsigned char c = (unsigned char)raw[pos]; ++c; - hash[pos] = (char) c; + raw[pos] = (char) c; if(c) break; } + hash=toBase32Hex(raw); } static void decrementHash(std::string& hash) // I wonder if this is correct, cmouse? ;-) { if(hash.empty()) return; - for(string::size_type pos=hash.size(); pos; ) { + + string raw=fromBase32Hex(hash); + for(string::size_type pos=raw.size(); pos; ) { --pos; - unsigned char c = (unsigned char)hash[pos]; + unsigned char c = (unsigned char)raw[pos]; --c; - hash[pos] = (char) c; + raw[pos] = (char) c; if(c != 0xff) break; } + hash = toBase32Hex(raw); }