Skip to content

Commit 8b379d4

Browse files
committed
Fix out-of-band access issue in iequals function
1 parent cc58816 commit 8b379d4

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

include/boost/beast/core/impl/string.ipp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,26 @@ iequals(
2323
beast::string_view lhs,
2424
beast::string_view rhs)
2525
{
26-
auto n = lhs.size();
27-
if(rhs.size() != n)
26+
if(lhs.size() != rhs.size())
2827
return false;
28+
auto n = lhs.size();
2929
auto p1 = lhs.data();
3030
auto p2 = rhs.data();
31-
char a, b;
3231
// fast loop
3332
while(n--)
3433
{
35-
a = *p1++;
36-
b = *p2++;
37-
if(a != b)
34+
if(*p1++ != *p2++)
3835
goto slow;
3936
}
4037
return true;
4138
slow:
39+
--p1;
40+
--p2;
4241
do
4342
{
44-
if( detail::ascii_tolower(a) !=
45-
detail::ascii_tolower(b))
43+
if( detail::ascii_tolower(*p1++) !=
44+
detail::ascii_tolower(*p2++))
4645
return false;
47-
a = *p1++;
48-
b = *p2++;
4946
}
5047
while(n--);
5148
return true;

0 commit comments

Comments
 (0)