Skip to content

Commit

Permalink
Move most of pdns_stou to Pdns::stoi and Pdns::stou
Browse files Browse the repository at this point in the history
This also creates the Pdns namespace and renames pdns_stou to Pdns::stou and separates
signed from unsigned conversion (Pdns::stoi and Pdns::stou) which are now implemented in
terms of Pdns::checked_conv and return a generic integer.
  • Loading branch information
fredmorcos committed Mar 15, 2022
1 parent dc00c1f commit a0383aa
Show file tree
Hide file tree
Showing 38 changed files with 205 additions and 128 deletions.
4 changes: 2 additions & 2 deletions modules/bindbackend/binddnssec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ bool Bind2Backend::getDomainKeys(const DNSName& name, std::vector<KeyData>& keys
SSqlStatement::row_t row;
while (d_getDomainKeysQuery_stmt->hasNextRow()) {
d_getDomainKeysQuery_stmt->nextRow(row);
kd.id = pdns_stou(row[0]);
kd.flags = pdns_stou(row[1]);
pdns::checked_stoi_into(kd.id, row[0]);
pdns::checked_stoi_into(kd.flags, row[1]);
kd.active = (row[2] == "1");
kd.published = (row[3] == "1");
kd.content = row[4];
Expand Down
16 changes: 8 additions & 8 deletions modules/geoipbackend/geoipbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,10 @@ bool GeoIPBackend::getDomainKeys(const DNSName& name, std::vector<DNSBackend::Ke
for (size_t i = 0; i < glob_result.gl_pathc; i++) {
if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
DNSBackend::KeyData kd;
kd.id = pdns_stou(glob_result.gl_pathv[i] + regm[3].rm_so);
pdns::checked_stoi_into(kd.id, glob_result.gl_pathv[i] + regm[3].rm_so);
kd.active = !strncmp(glob_result.gl_pathv[i] + regm[4].rm_so, "1", 1);
kd.published = true;
kd.flags = pdns_stou(glob_result.gl_pathv[i] + regm[2].rm_so);
pdns::checked_stoi_into(kd.flags, glob_result.gl_pathv[i] + regm[2].rm_so);
ifstream ifs(glob_result.gl_pathv[i]);
ostringstream content;
char buffer[1024];
Expand Down Expand Up @@ -968,7 +968,7 @@ bool GeoIPBackend::removeDomainKey(const DNSName& name, unsigned int id)
if (glob(pathname.str().c_str(), GLOB_ERR, NULL, &glob_result) == 0) {
for (size_t i = 0; i < glob_result.gl_pathc; i++) {
if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
unsigned int kid = pdns_stou(glob_result.gl_pathv[i] + regm[3].rm_so);
auto kid = pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[3].rm_so);
if (kid == id) {
if (unlink(glob_result.gl_pathv[i])) {
cerr << "Cannot delete key:" << strerror(errno) << endl;
Expand Down Expand Up @@ -1004,7 +1004,7 @@ bool GeoIPBackend::addDomainKey(const DNSName& name, const KeyData& key, int64_t
if (glob(pathname.str().c_str(), GLOB_ERR, NULL, &glob_result) == 0) {
for (size_t i = 0; i < glob_result.gl_pathc; i++) {
if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
unsigned int kid = pdns_stou(glob_result.gl_pathv[i] + regm[3].rm_so);
auto kid = pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[3].rm_so);
if (kid >= nextid)
nextid = kid + 1;
}
Expand Down Expand Up @@ -1040,10 +1040,10 @@ bool GeoIPBackend::activateDomainKey(const DNSName& name, unsigned int id)
if (glob(pathname.str().c_str(), GLOB_ERR, NULL, &glob_result) == 0) {
for (size_t i = 0; i < glob_result.gl_pathc; i++) {
if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
unsigned int kid = pdns_stou(glob_result.gl_pathv[i] + regm[3].rm_so);
auto kid = pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[3].rm_so);
if (kid == id && !strcmp(glob_result.gl_pathv[i] + regm[4].rm_so, "0")) {
ostringstream newpath;
newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns_stou(glob_result.gl_pathv[i] + regm[2].rm_so) << "." << kid << ".1.key";
newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[2].rm_so) << "." << kid << ".1.key";
if (rename(glob_result.gl_pathv[i], newpath.str().c_str())) {
cerr << "Cannot activate key: " << strerror(errno) << endl;
}
Expand Down Expand Up @@ -1075,10 +1075,10 @@ bool GeoIPBackend::deactivateDomainKey(const DNSName& name, unsigned int id)
if (glob(pathname.str().c_str(), GLOB_ERR, NULL, &glob_result) == 0) {
for (size_t i = 0; i < glob_result.gl_pathc; i++) {
if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
unsigned int kid = pdns_stou(glob_result.gl_pathv[i] + regm[3].rm_so);
auto kid = pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[3].rm_so);
if (kid == id && !strcmp(glob_result.gl_pathv[i] + regm[4].rm_so, "1")) {
ostringstream newpath;
newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns_stou(glob_result.gl_pathv[i] + regm[2].rm_so) << "." << kid << ".0.key";
newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns::checked_stoi<unsigned int>(glob_result.gl_pathv[i] + regm[2].rm_so) << "." << kid << ".0.key";
if (rename(glob_result.gl_pathv[i], newpath.str().c_str())) {
cerr << "Cannot deactivate key: " << strerror(errno) << endl;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/ldapbackend/ldapbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void LdapBackend::extract_entry_results(const DNSName& domain, const DNSResult&
if (qtype2 != QType(local_result.qtype).toString())
continue;

local_result.ttl = pdns_stou(rdata.substr(pos + 1));
pdns::checked_stoi_into(local_result.ttl, rdata.substr(pos + 1));
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/ldapbackend/native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ bool LdapBackend::getDomainInfo(const DNSName& domain, DomainInfo& di, bool getS
di.zone = DNSName(domain);

if (result.count("PdnsDomainLastCheck") && !result["PdnsDomainLastCheck"].empty())
di.last_check = pdns_stou(result["PdnsDomainLastCheck"][0]);
pdns::checked_stoi_into(di.last_check, result["PdnsDomainLastCheck"][0]);
else
di.last_check = 0;

if (result.count("PdnsDomainNotifiedSerial") && !result["PdnsDomainNotifiedSerial"].empty())
di.notified_serial = pdns_stou(result["PdnsDomainNotifiedSerial"][0]);
pdns::checked_stoi_into(di.notified_serial, result["PdnsDomainNotifiedSerial"][0]);
else
di.notified_serial = 0;

Expand Down
4 changes: 2 additions & 2 deletions modules/pipebackend/pipebackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ bool PipeBackend::get(DNSResourceRecord& r)
}
r.qname = DNSName(parts[1 + extraFields]);
r.qtype = parts[3 + extraFields];
r.ttl = pdns_stou(parts[4 + extraFields]);
r.domain_id = std::stoi(parts[5 + extraFields]);
pdns::checked_stoi_into(r.ttl, parts[4 + extraFields]);
pdns::checked_stoi_into(r.domain_id, parts[5 + extraFields]);

if (r.qtype.getCode() != QType::MX && r.qtype.getCode() != QType::SRV) {
r.content.clear();
Expand Down
40 changes: 20 additions & 20 deletions pdns/backends/gsql/gsqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_InfoOfAllSlaveDomainsQuery=getArg("info-all-slaves-query");
d_SuperMasterInfoQuery=getArg("supermaster-query");
d_GetSuperMasterIPs=getArg("supermaster-name-to-ips");
d_AddSuperMaster=getArg("supermaster-add");
d_AddSuperMaster=getArg("supermaster-add");
d_RemoveAutoPrimaryQuery=getArg("autoprimary-remove");
d_ListAutoPrimariesQuery=getArg("list-autoprimaries");
d_InsertZoneQuery=getArg("insert-zone-query");
Expand Down Expand Up @@ -110,7 +110,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_GetLastInsertedKeyIdQuery = getArg("get-last-inserted-key-id-query");
d_ListDomainKeysQuery = getArg("list-domain-keys-query");

d_GetAllDomainMetadataQuery = getArg("get-all-domain-metadata-query");
d_GetAllDomainMetadataQuery = getArg("get-all-domain-metadata-query");
d_GetDomainMetadataQuery = getArg("get-domain-metadata-query");
d_ClearDomainMetadataQuery = getArg("clear-domain-metadata-query");
d_ClearDomainAllMetadataQuery = getArg("clear-domain-all-metadata-query");
Expand Down Expand Up @@ -315,7 +315,7 @@ bool GSQLBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getS

ASSERT_ROW_COLUMNS("info-zone-query", d_result[0], 7);

di.id=pdns_stou(d_result[0][0]);
pdns::checked_stoi_into(di.id, d_result[0][0]);
try {
di.zone=DNSName(d_result[0][1]);
} catch (...) {
Expand All @@ -329,8 +329,8 @@ bool GSQLBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getS
stringtok(masters, d_result[0][2], " ,\t");
for(const auto& m : masters)
di.masters.emplace_back(m, 53);
di.last_check=pdns_stou(d_result[0][3]);
di.notified_serial = pdns_stou(d_result[0][4]);
pdns::checked_stoi_into(di.last_check, d_result[0][3]);
pdns::checked_stoi_into(di.notified_serial, d_result[0][4]);
di.backend=this;

di.serial = 0;
Expand Down Expand Up @@ -389,7 +389,7 @@ void GSQLBackend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
}

try {
sd.id=pdns_stou(row[0]);
pdns::checked_stoi_into(sd.id, row[0]);
} catch (const std::exception &e) {
g_log<<Logger::Warning<<"Could not convert id ("<<row[0]<<") for domain '"<<sd.zone<<"' into an integer: "<<e.what()<<endl;
continue;
Expand All @@ -410,7 +410,7 @@ void GSQLBackend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
}

try {
sd.last_check=pdns_stou(row[3]);
pdns::checked_stoi_into(sd.last_check, row[3]);
} catch (const std::exception &e) {
g_log<<Logger::Warning<<"Could not convert last_check ("<<row[3]<<") for domain '"<<sd.zone<<"' into an integer: "<<e.what()<<endl;
continue;
Expand Down Expand Up @@ -473,11 +473,11 @@ void GSQLBackend::getUpdatedMasters(vector<DomainInfo> *updatedDomains)
stringtok( parts, d_result[n][3] );

try {
uint32_t serial = parts.size() > 2 ? pdns_stou(parts[2]) : 0;
uint32_t notified_serial = pdns_stou( d_result[n][2] );
uint32_t serial = parts.size() > 2 ? pdns::checked_stoi<uint32_t>(parts[2]) : 0;
auto notified_serial = pdns::checked_stoi<uint32_t>(d_result[n][2]);

if( serial != notified_serial ) {
di.id = pdns_stou( d_result[n][0] );
pdns::checked_stoi_into(di.id, d_result[n][0]);
di.zone = DNSName( d_result[n][1] );
di.serial = serial;
di.notified_serial = notified_serial;
Expand Down Expand Up @@ -999,8 +999,8 @@ bool GSQLBackend::getDomainKeys(const DNSName& name, std::vector<KeyData>& keys)
//~ for(const auto& val: row) {
//~ cerr<<"'"<<val<<"'"<<endl;
//~ }
kd.id = pdns_stou(row[0]);
kd.flags = pdns_stou(row[1]);
pdns::checked_stoi_into(kd.id, row[0]);
pdns::checked_stoi_into(kd.flags, row[1]);
kd.active = row[2] == "1";
kd.published = row[3] == "1";
kd.content = row[4];
Expand Down Expand Up @@ -1453,7 +1453,7 @@ void GSQLBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, boo
d_getAllDomainsQuery_stmt->nextRow(row);
ASSERT_ROW_COLUMNS("get-all-domains-query", row, 8);
DomainInfo di;
di.id = pdns_stou(row[0]);
pdns::checked_stoi_into(di.id, row[0]);
try {
di.zone = DNSName(row[1]);
} catch (...) {
Expand Down Expand Up @@ -1495,8 +1495,8 @@ void GSQLBackend::getAllDomains(vector<DomainInfo>* domains, bool getSerial, boo
}

try {
di.notified_serial = pdns_stou(row[5]);
di.last_check = pdns_stou(row[6]);
pdns::checked_stoi_into(di.notified_serial, row[5]);
pdns::checked_stoi_into(di.last_check, row[6]);
} catch(...) {
continue;
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r, const DNSName &ordernam
if (r.qtype == QType::MX || r.qtype == QType::SRV) {
string::size_type pos = content.find_first_not_of("0123456789");
if (pos != string::npos) {
prio=pdns_stou(content.substr(0,pos));
pdns::checked_stoi_into(prio, content.substr(0,pos));
boost::erase_head(content, pos);
}
boost::trim_left(content);
Expand Down Expand Up @@ -1929,7 +1929,7 @@ void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)
if (row[1].empty())
r.ttl = defaultTTL;
else
r.ttl=pdns_stou(row[1]);
pdns::checked_stoi_into(r.ttl, row[1]);

if(!d_qname.empty())
r.qname=d_qname;
Expand Down Expand Up @@ -1958,7 +1958,7 @@ void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)

r.disabled = !row[5].empty() && row[5][0]=='1';

r.domain_id=pdns_stou(row[4]);
pdns::checked_stoi_into(r.domain_id, row[4]);

if (row.size() > 8) { // if column 8 exists, it holds an ordername
if (!row.at(8).empty()) {
Expand All @@ -1975,10 +1975,10 @@ void GSQLBackend::extractRecord(SSqlStatement::row_t& row, DNSResourceRecord& r)

void GSQLBackend::extractComment(SSqlStatement::row_t& row, Comment& comment)
{
comment.domain_id = pdns_stou(row[0]);
pdns::checked_stoi_into(comment.domain_id, row[0]);
comment.qname = DNSName(row[1]);
comment.qtype = row[2];
comment.modified_at = pdns_stou(row[3]);
pdns::checked_stoi_into(comment.modified_at, row[3]);
comment.account = std::move(row[4]);
comment.content = std::move(row[5]);
}
Expand Down
6 changes: 3 additions & 3 deletions pdns/credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ static void parseHashed(const std::string& hash, std::string& salt, std::string&
}

try {
workFactor = pdns_stou(parameters.at(0).substr(3));
workFactor = pdns::checked_stoi<uint64_t>(parameters.at(0).substr(3));
workFactor = static_cast<uint64_t>(1) << workFactor;
if (workFactor > pwhash_max_work_factor) {
throw std::runtime_error("Invalid work factor of " + std::to_string(workFactor) + " in hashed password string, maximum is " + std::to_string(pwhash_max_work_factor));
}

parallelFactor = pdns_stou(parameters.at(1).substr(2));
blockSize = pdns_stou(parameters.at(2).substr(2));
parallelFactor = pdns::checked_stoi<uint64_t>(parameters.at(1).substr(2));
blockSize = pdns::checked_stoi<uint64_t>(parameters.at(2).substr(2));

auto b64Salt = hash.substr(saltPos, saltEnd - saltPos);
salt.reserve(pwhash_salt_size);
Expand Down
4 changes: 2 additions & 2 deletions pdns/decafsigners.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void DecafED25519DNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::m
PrivateKey: ODIyNjAzODQ2MjgwODAxMjI2NDUxOTAyMDQxNDIyNjI=
*/

drc.d_algorithm = pdns_stou(stormap["algorithm"]);
pdns::checked_stoi_into(drc.d_algorithm, stormap["algorithm"]);
string privateKey = stormap["privatekey"];

if (privateKey.length() != DECAF_EDDSA_25519_PRIVATE_BYTES)
Expand Down Expand Up @@ -217,7 +217,7 @@ void DecafED448DNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::map
PrivateKey: xZ+5Cgm463xugtkY5B0Jx6erFTXp13rYegst0qRtNsOYnaVpMx0Z/c5EiA9x8wWbDDct/U3FhYWA
*/

drc.d_algorithm = pdns_stou(stormap["algorithm"]);
pdns::checked_stoi_into(drc.d_algorithm, stormap["algorithm"]);
string privateKey = stormap["privatekey"];

if (privateKey.length() != DECAF_EDDSA_448_PRIVATE_BYTES)
Expand Down
10 changes: 5 additions & 5 deletions pdns/dnsbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ void fillSOAData(const string &content, SOAData &data)
try {
data.nameserver = DNSName(parts.at(0));
data.hostmaster = DNSName(parts.at(1));
data.serial = pdns_stou(parts.at(2).c_str());
data.refresh = pdns_stou(parts.at(3).c_str());
data.retry = pdns_stou(parts.at(4).c_str());
data.expire = pdns_stou(parts.at(5).c_str());
data.minimum = pdns_stou(parts.at(6).c_str());
pdns::checked_stoi_into(data.serial, parts.at(2));
pdns::checked_stoi_into(data.refresh, parts.at(3));
pdns::checked_stoi_into(data.retry, parts.at(4));
pdns::checked_stoi_into(data.expire, parts.at(5));
pdns::checked_stoi_into(data.minimum, parts.at(6));
}
catch(const std::out_of_range& oor) {
throw PDNSException("Out of range exception parsing '" + content + "'");
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnsdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static bool applyRulesToResponse(LocalStateHolder<vector<DNSDistResponseRuleActi
break;
/* non-terminal actions follow */
case DNSResponseAction::Action::Delay:
dr.delayMsec = static_cast<int>(pdns_stou(ruleresult)); // sorry
pdns::checked_stoi_into(dr.delayMsec, ruleresult); // sorry
break;
case DNSResponseAction::Action::None:
break;
Expand Down Expand Up @@ -833,7 +833,7 @@ bool processRulesResult(const DNSAction::Action& action, DNSQuestion& dq, std::s
break;
/* non-terminal actions follow */
case DNSAction::Action::Delay:
dq.delayMsec = static_cast<int>(pdns_stou(ruleresult)); // sorry
pdns::checked_stoi_into(dq.delayMsec, ruleresult); // sorry
break;
case DNSAction::Action::None:
/* fall-through */
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-nghttp2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ int DoHConnectionToBackend::on_header_callback(nghttp2_session* session, const n
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
try {
stream->second.d_responseCode = pdns_stou(std::string(reinterpret_cast<const char*>(value), valuelen));
pdns::checked_stoi_into(stream->second.d_responseCode, std::string(reinterpret_cast<const char*>(value), valuelen));
}
catch (...) {
vinfolog("Error parsing the status header for stream ID %d", frame->hd.stream_id);
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ UnknownRecordContent::UnknownRecordContent(const string& zone)
}

const string& relevant = (parts.size() > 2) ? parts.at(2) : "";
unsigned int total = pdns_stou(parts.at(1));
auto total = pdns::checked_stoi<unsigned int>(parts.at(1));
if (relevant.size() % 2 || (relevant.size() / 2) != total) {
throw MOADNSException((boost::format("invalid unknown record length: size not equal to length field (%d != 2 * %d)") % relevant.size() % total).str());
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsparser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public:
return iter->second.second;

if (isUnknownType(name)) {
return (uint16_t)pdns_stou(name.substr(4));
return pdns::checked_stoi<uint16_t>(name.substr(4));
}

throw runtime_error("Unknown DNS type '"+name+"'");
Expand Down
4 changes: 2 additions & 2 deletions pdns/dnssecinfra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::unique_ptr<DNSCryptoKeyEngine> DNSCryptoKeyEngine::makeFromISCString(DNSKEY
}
else if (it->second == KeyTypes::numeric) {
try {
unsigned int num = pdns_stou(value);
auto num = pdns::checked_stoi<unsigned int>(value);
stormap[key] = std::to_string(num);
if (key == "algorithm") {
algorithm = num;
Expand Down Expand Up @@ -306,7 +306,7 @@ void DNSCryptoKeyEngine::testMakers(unsigned int algo, maker_t* creator, maker_t
std::tie(key,value)=splitField(sline, ':');
boost::trim(value);
if(pdns_iequals(key,"algorithm")) {
algorithm = pdns_stou(value);
pdns::checked_stoi_into(algorithm, value);
stormap["algorithm"]=std::to_string(algorithm);
continue;
} else if (pdns_iequals(key,"pin")) {
Expand Down
2 changes: 1 addition & 1 deletion pdns/dynloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main(int argc, char **argv)
else {
uint16_t port;
try {
port = static_cast<uint16_t>(pdns_stou(::arg()["remote-port"]));
pdns::checked_stoi_into(port, ::arg()["remote-port"]);
}
catch(...) {
cerr<<"Unable to convert '"<<::arg()["remote-port"]<<"' to a port number for connecting to remote PowerDNS\n";
Expand Down
4 changes: 2 additions & 2 deletions pdns/iputils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ ComboAddress parseIPAndPort(const std::string& input, uint16_t port)
{
if (input[0] == '[') { // case 1
auto both = splitField(input.substr(1), ']');
return ComboAddress(both.first, both.second.empty() ? port : static_cast<uint16_t>(pdns_stou(both.second.substr(1))));
return ComboAddress(both.first, both.second.empty() ? port : pdns::checked_stoi<uint16_t>(both.second.substr(1)));
}

string::size_type count = 0;
Expand All @@ -527,7 +527,7 @@ ComboAddress parseIPAndPort(const std::string& input, uint16_t port)
both.first = input.substr(0, cpos);
both.second = input.substr(cpos + 1);

uint16_t newport = static_cast<uint16_t>(pdns_stou(both.second));
auto newport = pdns::checked_stoi<uint16_t>(both.second);
return ComboAddress(both.first, newport);
}
default: // case 4
Expand Down
2 changes: 1 addition & 1 deletion pdns/iputils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public:
d_network = makeComboAddress(split.first);

if (!split.second.empty()) {
setBits(static_cast<uint8_t>(pdns_stou(split.second)));
setBits(pdns::checked_stoi<uint8_t>(split.second));
}
else if (d_network.sin4.sin_family == AF_INET) {
setBits(32);
Expand Down
Loading

0 comments on commit a0383aa

Please sign in to comment.