From e358efcb6cb78f6596044fee04820480ad60ef1f Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 26 Apr 2016 17:20:07 +0200 Subject: [PATCH] Use unsigned char* in getRawLabels() and countLabels() Otherwise we treat values larger than INT8_MAX as negatives in pointer arithmetic. Found with American Fuzzy Lop and Address Sanitizer. --- pdns/dnsname.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 55849c5a9..f438a0068 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -290,8 +290,9 @@ vector DNSName::getRawLabels() const vector ret; ret.reserve(countLabels()); // 3www4ds9a2nl0 - for(const char* p = d_storage.c_str(); p < d_storage.c_str() + d_storage.size() && *p; p+=*p+1) - ret.push_back({p+1, (unsigned int)*p}); // XXX FIXME + for(const unsigned char* p = (const unsigned char*) d_storage.c_str(); p < ((const unsigned char*) d_storage.c_str()) + d_storage.size() && *p; p+=*p+1) { + ret.push_back({(const char*)p+1, (size_t)*p}); // XXX FIXME + } return ret; } @@ -315,7 +316,7 @@ bool DNSName::isWildcard() const unsigned int DNSName::countLabels() const { unsigned int count=0; - for(const char* p = d_storage.c_str(); p < d_storage.c_str() + d_storage.size() && *p; p+=*p+1) + for(const unsigned char* p = (const unsigned char*) d_storage.c_str(); p < ((const unsigned char*) d_storage.c_str()) + d_storage.size() && *p; p+=*p+1) ++count; return count; } -- 2.40.0