]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Replace a bunch of std::stoi with pdns::checked_stoi. 17389/head
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 18 May 2026 07:31:47 +0000 (09:31 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 18 May 2026 07:31:47 +0000 (09:31 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/bindbackend/binddnssec.cc
modules/pipebackend/pipebackend.cc
pdns/backends/gsql/gsqlbackend.cc
pdns/dnssecinfra.cc
pdns/json.cc
pdns/minicurl.cc
pdns/pkcs11signers.cc
pdns/ws-auth.cc

index 29fcd049108a6905c1cc229e321c8d0c178eeb4b..a92f936377af8b18a894b19f65992bdc72b53028 100644 (file)
@@ -384,7 +384,7 @@ bool Bind2Backend::addDomainKey(const ZoneName& name, const KeyData& key, int64_
     SSqlStatement::row_t row;
     d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
     ASSERT_ROW_COLUMNS("get-last-inserted-key-id-query", row, 1);
-    keyId = std::stoi(row[0]);
+    pdns::checked_stoi_into(keyId, row[0]);
     d_GetLastInsertedKeyIdQuery_stmt->reset();
     if (keyId == 0) {
       // No insert took place, report as error.
index 75e6cd5555e88da3e1875c815c08859c2cb0f0ec..274f62ea11bf938b9035419a2853ef5c10c1f53d 100644 (file)
@@ -320,7 +320,7 @@ bool PipeBackend::get(DNSResourceRecord& r)
         }
 
         if (d_abiVersion >= 3) {
-          r.scopeMask = std::stoi(parts[1]);
+          pdns::checked_stoi_into(r.scopeMask, parts[1]);
           r.auth = (parts[2] == "1");
           parts.erase(parts.begin() + 1, parts.begin() + 3);
         }
index 3513eee483e2192c2208fcb65f43910df264ae37..b58d741dcecadaaa4c6e61c29254e8ac5b214897 100644 (file)
@@ -1066,7 +1066,7 @@ bool GSQLBackend::addDomainKey(const ZoneName& name, const KeyData& key, int64_t
     if (d_AddDomainKeyQuery_stmt->hasNextRow()) {
       SSqlStatement::row_t row;
       d_AddDomainKeyQuery_stmt->nextRow(row);
-      keyId = std::stoi(row[0]);
+      pdns::checked_stoi_into(keyId, row[0]);
       d_AddDomainKeyQuery_stmt->reset();
       return true;
     } else {
@@ -1088,7 +1088,7 @@ bool GSQLBackend::addDomainKey(const ZoneName& name, const KeyData& key, int64_t
     SSqlStatement::row_t row;
     d_GetLastInsertedKeyIdQuery_stmt->nextRow(row);
     ASSERT_ROW_COLUMNS("get-last-inserted-key-id-query", row, 1);
-    keyId = std::stoi(row[0]);
+    pdns::checked_stoi_into(keyId, row[0]);
     d_GetLastInsertedKeyIdQuery_stmt->reset();
     if (keyId == 0) {
       // No insert took place, report as error.
index ffdea63a08378429e276543b277d6575a7f197fb..fc0758d7c3b18230cec4920a668845718ab3cba1 100644 (file)
@@ -343,7 +343,7 @@ static map<string, string> ISCStringtoMap(const string& argStr)
       continue;
     }
     if (pdns_iequals(key,"slot")) {
-      int slot = std::stoi(value);
+      auto slot = pdns::checked_stoi<int>(value);
       stormap["slot"]=std::to_string(slot);
       continue;
     }
index 457f09b0ba77caaa9879d133e67385ba95cf9a12..6a0b296139bec96cb1795d0c1fc6720919416c95 100644 (file)
@@ -37,7 +37,7 @@ static inline int intFromJsonInternal(const Json& container, const std::string&
 
   if (val.is_string()) {
     try {
-      return std::stoi(val.string_value());
+      return pdns::checked_stoi<int>(val.string_value());
     } catch (std::logic_error&) {
       throw JsonException("Key '" + string(key) + "' is not a valid number");
     }
index bc975a91591c0f13f7efec741237de8d60762f12..c1182cb126b80bfbf31b5a83e13561f5f6d97b5c 100644 (file)
@@ -136,10 +136,8 @@ void MiniCurl::setupURL(const std::string& str, const ComboAddress* rem, const C
     std::size_t found = host4.find(':');
     vector<uint16_t> ports{80, 443};
     if (found != std::string::npos) {
-      int port = std::stoi(host4.substr(found + 1));
-      if (port <= 0 || port > 65535)
-        throw std::overflow_error("Invalid port number");
-      ports = {(uint16_t)port};
+      auto port = pdns::checked_stoi<uint16_t>(host4.substr(found + 1));
+      ports = {port};
       host4 = host4.substr(0, found);
     }
 
index a2566b587372ce653ceb40649049e05d1a2a3a87..d11f7f615f0f10788bb4e7ff044cf57a5f20e779 100644 (file)
@@ -723,7 +723,7 @@ CK_RV Pkcs11Slot::HuntSlot(Logr::log_t slog, const string& tokenId, CK_SLOT_ID &
 
   // see if we can find it with slotId
   try {
-    slotId = std::stoi(tokenId);
+    pdns::checked_stoi_into(slotId, tokenId);
     if ((err = functions->C_GetSlotInfo(slotId, info))) {
       SLOG(g_log<<Logger::Warning<<"C_GetSlotInfo("<<slotId<<", info) = " << err << std::endl,
            slog->info(Logr::Warning, "C_GetSlotInfo failed", "slotId", Logging::Loggable(slotId), "errorcode", Logging::Loggable(err)));
index a0920cddd42e9b6b66c31503ea68fcc146e5e0bf..ddc8aeb439e736508e036d0ab05d0b6419f7e176 100644 (file)
@@ -1352,7 +1352,7 @@ static inline int getInquireKeyId(HttpRequest* req, const ZoneName& zonename, DN
 {
   int inquireKeyId = -1;
   if (req->parameters.count("key_id") == 1) {
-    inquireKeyId = std::stoi(req->parameters["key_id"]);
+    pdns::checked_stoi_into(inquireKeyId, req->parameters["key_id"]);
     apiZoneCryptoKeysCheckKeyExists(zonename, inquireKeyId, dnsseckeeper);
   }
   return inquireKeyId;