From: Itecz Solution Date: Mon, 20 Jul 2026 17:52:41 +0000 (+0530) Subject: Do not pass signed char to ctype functions in text parsers X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43f5c3df30b5f255bd09bf985be6f01d358b5690;p=thirdparty%2Fpdns.git Do not pass signed char to ctype functions in text parsers Signed-off-by: Itecz Solution --- diff --git a/pdns/qtype.cc b/pdns/qtype.cc index bfad243acd..f73d950092 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -160,7 +160,7 @@ uint16_t QType::chartocode(const char *p) // not all callers are ready to handle exceptions arising here. char *end{nullptr}; unsigned long typeno = strtoul(digits, &end, 10); - if (typeno <= std::numeric_limits::max() && end != digits && (*end == '\0' || isspace(static_cast(*end)) != 0)) { + if (typeno <= std::numeric_limits::max() && end != digits && (*end == '\0' || isspace(static_cast(*end)) != 0)) { return typeno; } } diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index 0c0ce07e46..037e614454 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -58,7 +58,7 @@ void RecordTextReader::xfrNodeOrLocatorID(NodeOrLocatorID& val) { skipSpaces(); size_t len; for(len=0; - d_pos+len < d_string.length() && (isxdigit(d_string.at(d_pos+len)) || d_string.at(d_pos+len) == ':'); + d_pos+len < d_string.length() && (isxdigit(static_cast(d_string.at(d_pos+len))) || d_string.at(d_pos+len) == ':'); len++) ; // find length of ID // Parse as v6, and then strip the final 64 zero bytes @@ -77,7 +77,7 @@ void RecordTextReader::xfr64BitInt(uint64_t &val) { skipSpaces(); - if(!isdigit(d_string.at(d_pos))) + if(!isdigit(static_cast(d_string.at(d_pos)))) throw RecordTextException("expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); size_t pos; @@ -91,7 +91,7 @@ void RecordTextReader::xfr32BitInt(uint32_t &val) { skipSpaces(); - if(!isdigit(d_string.at(d_pos))) + if(!isdigit(static_cast(d_string.at(d_pos)))) throw RecordTextException("expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); size_t pos; @@ -141,7 +141,7 @@ void RecordTextReader::xfrIP(uint32_t &val) { skipSpaces(); - if(!isdigit(d_string.at(d_pos))) + if(!isdigit(static_cast(d_string.at(d_pos)))) throw RecordTextException("while parsing IP address, expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); uint32_t octet=0; @@ -161,7 +161,7 @@ void RecordTextReader::xfrIP(uint32_t &val) if(count > 3) throw RecordTextException(string("unable to parse IP address, too many dots")); } - else if(isdigit(d_string.at(d_pos))) { + else if(isdigit(static_cast(d_string.at(d_pos)))) { last_was_digit = true; octet*=10; octet+=d_string.at(d_pos) - '0'; @@ -196,7 +196,7 @@ void RecordTextReader::xfrIP6(std::string &val) size_t len; // lookup end of value - think of ::ffff encoding too, has dots in it! for(len=0; - d_pos+len < d_string.length() && (isxdigit(d_string.at(d_pos+len)) || d_string.at(d_pos+len) == ':' || d_string.at(d_pos+len)=='.'); + d_pos+len < d_string.length() && (isxdigit(static_cast(d_string.at(d_pos+len))) || d_string.at(d_pos+len) == ':' || d_string.at(d_pos+len)=='.'); len++); if(!len) @@ -633,7 +633,7 @@ static void HEXDecode(std::string_view chunk, string& out) bool lowdigit{false}; uint8_t val{0}; for (auto chr : chunk) { - if(isalnum(chr) == 0) { + if(isalnum(static_cast(chr)) == 0) { continue; } if (!lowdigit) { diff --git a/pdns/sillyrecords.cc b/pdns/sillyrecords.cc index 40d77add4a..7f2a2dfcea 100644 --- a/pdns/sillyrecords.cc +++ b/pdns/sillyrecords.cc @@ -25,7 +25,7 @@ enum coordtype { LATITUDE, LONGITUDE }; static void skipspace(const std::string& content, std::string::size_type& pos) { - while (pos < content.length() && std::isspace(content.at(pos)) != 0) { + while (pos < content.length() && std::isspace(static_cast(content.at(pos))) != 0) { ++pos; } } @@ -54,7 +54,7 @@ parsenum(const std::string& content, std::string::size_type& pos, unsigned int& bool parsed{false}; number = 0; - while (pos < content.length() && std::isdigit(content.at(pos)) != 0) { + while (pos < content.length() && std::isdigit(static_cast(content.at(pos))) != 0) { parsed = true; number = number * 10 + (content.at(pos) - '0'); ++pos; @@ -75,14 +75,14 @@ parsefrac(const std::string& content, std::string::size_type& pos, unsigned int ++pos; while (digits-- != 0) { number *= 10; - if (pos < content.length() && std::isdigit(content.at(pos)) != 0) { + if (pos < content.length() && std::isdigit(static_cast(content.at(pos))) != 0) { parsed = true; // intentionally rejects '.' alone number += (content.at(pos) - '0'); ++pos; } } // skip any further digits - while (pos < content.length() && std::isdigit(content.at(pos)) != 0) { + while (pos < content.length() && std::isdigit(static_cast(content.at(pos))) != 0) { ++pos; } } diff --git a/pdns/zoneparser-tng.cc b/pdns/zoneparser-tng.cc index dd6fd8fb27..ad1605a126 100644 --- a/pdns/zoneparser-tng.cc +++ b/pdns/zoneparser-tng.cc @@ -143,7 +143,7 @@ unsigned int ZoneParserTNG::makeTTLFromZone(const string& str) } char lc=dns_tolower(str[str.length()-1]); - if(!isdigit(lc)) + if(!isdigit(static_cast(lc))) switch(lc) { case 's': break;