Skip to content

Commit

Permalink
Merge r236969 - StringTypeAdapter constructor is not properly enforci…
Browse files Browse the repository at this point in the history
…ng String::MaxLength.

https://bugs.webkit.org/show_bug.cgi?id=190392
<rdar://problem/45116210>

Reviewed by Saam Barati.

Previously, the StringTypeAdapter constructor for a UChar* string was summing the
unsigned length of the source string without an overflow check.  We now make that
length a size_t which removes this issue, and assert that it's within
String::MaxLength thereafter.

Also made the StringTypeAdapter constructor for a LChar* string behave in an
equivalent manner for consistency.  In both cases, we'll crash in a RELEASE_ASSERT
if the source string length exceeds String::MaxLength.

* wtf/text/StringConcatenate.h:
  • Loading branch information
Mark Lam authored and mcatanzaro committed Dec 8, 2018
1 parent d5cde6c commit 0e1af67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,22 @@
2018-10-09 Mark Lam <mark.lam@apple.com>

StringTypeAdapter constructor is not properly enforcing String::MaxLength.
https://bugs.webkit.org/show_bug.cgi?id=190392
<rdar://problem/45116210>

Reviewed by Saam Barati.

Previously, the StringTypeAdapter constructor for a UChar* string was summing the
unsigned length of the source string without an overflow check. We now make that
length a size_t which removes this issue, and assert that it's within
String::MaxLength thereafter.

Also made the StringTypeAdapter constructor for a LChar* string behave in an
equivalent manner for consistency. In both cases, we'll crash in a RELEASE_ASSERT
if the source string length exceeds String::MaxLength.

* wtf/text/StringConcatenate.h:

2018-10-03 Mark Lam <mark.lam@apple.com>

Make string MaxLength for all WTF and JS strings consistently equal to INT_MAX.
Expand Down
9 changes: 5 additions & 4 deletions Source/WTF/wtf/text/StringConcatenate.h
Expand Up @@ -108,8 +108,10 @@ class StringTypeAdapter<const LChar*, void> {
public:
StringTypeAdapter(const LChar* characters)
: m_characters(characters)
, m_length(strlen(reinterpret_cast<const char*>(characters)))
{
size_t length = strlen(reinterpret_cast<const char*>(characters));
RELEASE_ASSERT(length <= String::MaxLength);
m_length = static_cast<unsigned>(length);
}

unsigned length() const { return m_length; }
Expand Down Expand Up @@ -138,12 +140,11 @@ class StringTypeAdapter<const UChar*, void> {
StringTypeAdapter(const UChar* characters)
: m_characters(characters)
{
unsigned length = 0;
size_t length = 0;
while (m_characters[length])
++length;

RELEASE_ASSERT(length <= String::MaxLength);
m_length = length;
m_length = static_cast<unsigned>(length);
}

unsigned length() const { return m_length; }
Expand Down

0 comments on commit 0e1af67

Please sign in to comment.