Skip to content

Commit

Permalink
Fix out-of-band access issue in iequals function
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed Dec 16, 2024
1 parent cc58816 commit 8b379d4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions include/boost/beast/core/impl/string.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8b379d4

Please sign in to comment.