fix(Core/IPLocation): Prevent crash when parsing invalid IP (#25095)
This commit is contained in:
parent
b872409411
commit
c947a51ecb
1 changed files with 13 additions and 6 deletions
|
|
@ -107,17 +107,24 @@ void IpLocationStore::Load()
|
|||
|
||||
IpLocationRecord const* IpLocationStore::GetLocationRecord(std::string const& ipAddress) const
|
||||
{
|
||||
uint32 ip = Acore::Net::address_to_uint(Acore::Net::make_address_v4(ipAddress));
|
||||
auto itr = std::upper_bound(_ipLocationStore.begin(), _ipLocationStore.end(), ip, [](uint32 ip, IpLocationRecord const& loc) { return ip < loc.IpTo; });
|
||||
if (itr == _ipLocationStore.end())
|
||||
uint32 ip;
|
||||
|
||||
try
|
||||
{
|
||||
ip = Acore::Net::address_to_uint(Acore::Net::make_address_v4(ipAddress));
|
||||
}
|
||||
catch (boost::system::system_error const&)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (ip < itr->IpFrom)
|
||||
{
|
||||
auto itr = std::upper_bound(_ipLocationStore.begin(), _ipLocationStore.end(), ip, [](uint32 ip, IpLocationRecord const& loc) { return ip < loc.IpTo; });
|
||||
|
||||
if (itr == _ipLocationStore.end())
|
||||
return nullptr;
|
||||
|
||||
if (ip < itr->IpFrom)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &(*itr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue