Ignore:
Timestamp:
Feb 19, 2010, 3:36:09 PM (15 years ago)
Author:
[email protected]
Message:

JSString::getIndex() calls value() to resolve the string value (is a rope)
to a UString, then passes the result to jsSingleCharacterSubstring without
checking for an exception. In case of out-of-memory the returned UString
is null(), which may result in an out-of-buounds substring being created.
This is bad.

Reviewed by Oliver Hunt.

Simple fix is to be able to get an index from a rope without resolving to
UString. This may be a useful optimization in some test cases.

The same bug exists in some other methods is JSString, these can be fixed
by changing them to call getIndex().

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::jsSingleCharacterSubstring):
(JSC::JSString::getIndex):
(JSC::jsSingleCharacterString):
(JSC::JSString::getStringPropertySlot):

  • runtime/UStringImpl.cpp:

(JSC::singleCharacterSubstring):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::singleCharacterSubstring):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSString.cpp

    r54843 r55035  
    5151        m_value = newImpl;
    5252    else {
    53         for (unsigned i = 0; i < m_fiberCount; ++i) {
    54             m_other.m_fibers[i]->deref();
    55             m_other.m_fibers[i] = 0;
    56         }
    57         m_fiberCount = 0;
    58         ASSERT(!isRope());
    59         ASSERT(m_value == UString());
    6053        throwOutOfMemoryError(exec);
    6154        return;
     
    188181    unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
    189182    if (isStrictUInt32 && i < m_length) {
    190         descriptor.setDescriptor(jsSingleCharacterSubstring(exec, value(exec), i), DontDelete | ReadOnly);
     183        descriptor.setDescriptor(getIndex(exec, i), DontDelete | ReadOnly);
    191184        return true;
    192185    }
Note: See TracChangeset for help on using the changeset viewer.