Skip to content

Commit c947a51

Browse files
authored
fix(Core/IPLocation): Prevent crash when parsing invalid IP (azerothcore#25095)
1 parent b872409 commit c947a51

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/common/IPLocation/IPLocation.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,24 @@ void IpLocationStore::Load()
107107

108108
IpLocationRecord const* IpLocationStore::GetLocationRecord(std::string const& ipAddress) const
109109
{
110-
uint32 ip = Acore::Net::address_to_uint(Acore::Net::make_address_v4(ipAddress));
111-
auto itr = std::upper_bound(_ipLocationStore.begin(), _ipLocationStore.end(), ip, [](uint32 ip, IpLocationRecord const& loc) { return ip < loc.IpTo; });
112-
if (itr == _ipLocationStore.end())
110+
uint32 ip;
111+
112+
try
113+
{
114+
ip = Acore::Net::address_to_uint(Acore::Net::make_address_v4(ipAddress));
115+
}
116+
catch (boost::system::system_error const&)
113117
{
114118
return nullptr;
115119
}
116120

121+
auto itr = std::upper_bound(_ipLocationStore.begin(), _ipLocationStore.end(), ip, [](uint32 ip, IpLocationRecord const& loc) { return ip < loc.IpTo; });
122+
123+
if (itr == _ipLocationStore.end())
124+
return nullptr;
125+
117126
if (ip < itr->IpFrom)
118-
{
119127
return nullptr;
120-
}
121128

122129
return &(*itr);
123130
}

0 commit comments

Comments
 (0)