]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Reject trailing hex digits in createforward 1-2-3-4 format.
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 9 Apr 2026 10:10:55 +0000 (12:10 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 9 Apr 2026 10:10:55 +0000 (12:10 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/lua-record.cc

index 090f376eb0f87ea76b96b5169310377d111dae7a..8d80a32a23232749471de150c372c3154eace3c2 100644 (file)
@@ -1106,12 +1106,13 @@ static string lua_createForward()
         string ret;
         for (size_t index=4; index > 0; index--) {
           const auto octet = ip_parts.at(ip_parts.size() - index);
-          auto octetVal = std::stol(octet); // may throw
-          if (octetVal >= 0 && octetVal <= 255) {
-            ret += octet + ".";
-          } else {
+          size_t octetLength{0};
+          auto octetVal = pdns::checked_stoi<uint8_t>(octet, &octetLength); // may throw
+
+          if (octetLength != octet.length()) { // trailing chars after number
             return allZerosIP;
           }
+          ret += std::to_string(octetVal) + ".";
         }
         ret.resize(ret.size() - 1); // remove trailing dot after last octet
         return ret;
@@ -1131,7 +1132,7 @@ static string lua_createForward()
     return allZerosIP;
   } catch (const PDNSException &) {
     return allZerosIP;
-  } catch (const std::exception &) { // thrown by std::stol
+  } catch (const std::exception &) { // thrown by pdns::checked_stoi
     return allZerosIP;
   }
 }