Skip to content

Commit

Permalink
AK: Don't compare past '\0' in StringView::operator==(const char*)
Browse files Browse the repository at this point in the history
We kept scanning the needle string even after hitting a null terminator
and that's clearly not right.

Found by oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31338
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31351
  • Loading branch information
awesomekling committed Feb 24, 2021
1 parent 9bc3c3c commit 42133a1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AK/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class StringView {
// NOTE: `m_characters` is not guaranteed to be null-terminated, but `cstring` is.
const char* cp = cstring;
for (size_t i = 0; i < m_length; ++i) {
if (!*cp)
return false;
if (m_characters[i] != *(cp++))
return false;
}
Expand Down

0 comments on commit 42133a1

Please sign in to comment.