Ignore:
Timestamp:
Oct 8, 2010, 12:38:12 PM (15 years ago)
Author:
[email protected]
Message:

2010-10-08 Chris Evans <[email protected]>

Reviewed by David Levin.

https://bugs.webkit.org/show_bug.cgi?id=47393

Use unsigned consistently to check for max StringImpl length.
Add a few integer overflow checks.
Uses the existing paradigm of CRASH() when we can't reasonably handle a crazily large request.

  • wtf/text/WTFString.cpp:
  • wtf/text/StringImpl.h:
  • wtf/text/StringImpl.cpp: Better use of size_t vs. unsigned; check for integer overflows.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/text/WTFString.cpp

    r67012 r69414  
    4949        return;
    5050       
    51     int len = 0;
     51    size_t len = 0;
    5252    while (str[len] != UChar(0))
    5353        len++;
     54
     55    if (len > std::numeric_limits<unsigned>::max())
     56        CRASH();
    5457   
    5558    m_impl = StringImpl::create(str, len);
     
    176179    ASSERT(charactersToAppend);
    177180    UChar* data;
     181    if (lengthToAppend > std::numeric_limits<unsigned>::max() - length())
     182        CRASH();
    178183    RefPtr<StringImpl> newImpl =
    179184        StringImpl::createUninitialized(length() + lengthToAppend, data);
     
    197202    ASSERT(charactersToInsert);
    198203    UChar* data;
     204    if (lengthToInsert > std::numeric_limits<unsigned>::max() - length())
     205        CRASH();
    199206    RefPtr<StringImpl> newImpl =
    200207      StringImpl::createUninitialized(length() + lengthToInsert, data);
     
    719726String String::fromUTF8(const char* stringStart, size_t length)
    720727{
     728    if (length > std::numeric_limits<unsigned>::max())
     729        CRASH();
     730
    721731    if (!stringStart)
    722732        return String();
Note: See TracChangeset for help on using the changeset viewer.