]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Do not pass signed char to ctype functions in text parsers
authorItecz Solution <support@itecz.au>
Mon, 20 Jul 2026 17:52:41 +0000 (23:22 +0530)
committerItecz Solution <support@itecz.au>
Mon, 20 Jul 2026 17:52:41 +0000 (23:22 +0530)
Signed-off-by: Itecz Solution <support@itecz.au>
pdns/qtype.cc
pdns/rcpgenerator.cc
pdns/sillyrecords.cc
pdns/zoneparser-tng.cc

index bfad243acdc829e96325e67377504946af75462f..f73d9500929fa5c65f54d94bc301bc60b2a6e37a 100644 (file)
@@ -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<uint16_t>::max() && end != digits && (*end == '\0' || isspace(static_cast<int>(*end)) != 0)) {
+   if (typeno <= std::numeric_limits<uint16_t>::max() && end != digits && (*end == '\0' || isspace(static_cast<unsigned char>(*end)) != 0)) {
      return typeno;
    }
   }
index 0c0ce07e46a931dca97da7d569e14e79f1d0a420..037e614454623059e821d252183a0810c6ca8370 100644 (file)
@@ -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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(chr)) == 0) {
       continue;
     }
     if (!lowdigit) {
index 40d77add4aee90d0586ef9d5ec8f1ddda880f80c..7f2a2dfcea88a315861fa62e52f4ccca90254bac 100644 (file)
@@ -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<unsigned char>(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<unsigned char>(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<unsigned char>(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<unsigned char>(content.at(pos))) != 0) {
       ++pos;
     }
   }
index dd6fd8fb273600ca1450e375e0fdf277fe640764..ad1605a126381591270ccd524db90a4fa3e6d9bb 100644 (file)
@@ -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<unsigned char>(lc)))
     switch(lc) {
     case 's':
       break;