Fix out-of-band access issue in iequals function

This commit is contained in:
Mohammad Nejati
2024-12-15 08:29:50 +00:00
committed by Mohammad Nejati
parent cc58816ffc
commit 8b379d4fb1

View File

@ -23,29 +23,26 @@ iequals(
beast::string_view lhs,
beast::string_view rhs)
{
auto n = lhs.size();
if(rhs.size() != n)
if(lhs.size() != rhs.size())
return false;
auto n = lhs.size();
auto p1 = lhs.data();
auto p2 = rhs.data();
char a, b;
// fast loop
while(n--)
{
a = *p1++;
b = *p2++;
if(a != b)
if(*p1++ != *p2++)
goto slow;
}
return true;
slow:
--p1;
--p2;
do
{
if( detail::ascii_tolower(a) !=
detail::ascii_tolower(b))
if( detail::ascii_tolower(*p1++) !=
detail::ascii_tolower(*p2++))
return false;
a = *p1++;
b = *p2++;
}
while(n--);
return true;