diff --git a/pdns/dnslabeltext.rl b/pdns/dnslabeltext.rl index 87a5799672f6..27f435094dc2 100644 --- a/pdns/dnslabeltext.rl +++ b/pdns/dnslabeltext.rl @@ -108,11 +108,11 @@ DNSName::string_t segmentDNSNameRaw(const char* realinput, size_t inputlen) const char* eof = pe; int cs; char val = 0; - char labellen=0; + unsigned char labellen=0; unsigned int lenpos=0; %%{ action labelEnd { - if (labellen < 0 || labellen > 63) { + if (labellen > 63) { throw runtime_error("Unable to parse DNS name '"+string(realinput)+"': invalid label length "+std::to_string(labellen)); } ret[lenpos]=labellen; diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index c2b48e9fd773..22e2cf9f5774 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -255,8 +255,8 @@ bool DNSName::isPartOf(const DNSName& parent) const } return true; } - if (*us < 0) { - throw std::out_of_range("negative label length in dnsname"); + if (static_cast(*us) > 63) { + throw std::out_of_range("illegal label length in dnsname"); } } return false;