⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243246 in webkit


Ignore:
Timestamp:
Mar 20, 2019, 3:12:12 PM (7 years ago)
Author:
Tadeu Zagallo
Message:

JSC::createError needs to check for OOM in errorDescriptionForValue
https://bugs.webkit.org/show_bug.cgi?id=196032
<rdar://problem/46842740>

Reviewed by Mark Lam.

JSTests:

  • stress/create-error-out-of-memory-rope-string.js: Added.

Source/JavaScriptCore:

We were missing exceptions checks at two levels:

  • In errorDescriptionForValue, when the value is a string, we should check that JSString::value returns a valid string, since we might run out of memory if it is a rope and we need to resolve it.
  • In createError, we should check for the result of errorDescriptionForValue before concatenating it with the message provided by the caller.
  • runtime/ExceptionHelpers.cpp:

(JSC::errorDescriptionForValue):
(JSC::createError):

  • runtime/ExceptionHelpers.h:
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r243191 r243246  
     12019-03-20  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        JSC::createError needs to check for OOM in errorDescriptionForValue
     4        https://bugs.webkit.org/show_bug.cgi?id=196032
     5        <rdar://problem/46842740>
     6
     7        Reviewed by Mark Lam.
     8
     9        * stress/create-error-out-of-memory-rope-string.js: Added.
     10
    1112019-03-19  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r243244 r243246  
     12019-03-20  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        JSC::createError needs to check for OOM in errorDescriptionForValue
     4        https://bugs.webkit.org/show_bug.cgi?id=196032
     5        <rdar://problem/46842740>
     6
     7        Reviewed by Mark Lam.
     8
     9        We were missing exceptions checks at two levels:
     10        - In errorDescriptionForValue, when the value is a string, we should
     11          check that JSString::value returns a valid string, since we might run
     12          out of memory if it is a rope and we need to resolve it.
     13        - In createError, we should check for the result of errorDescriptionForValue
     14          before concatenating it with the message provided by the caller.
     15
     16        * runtime/ExceptionHelpers.cpp:
     17        (JSC::errorDescriptionForValue):
     18        (JSC::createError):
     19        * runtime/ExceptionHelpers.h:
     20
    1212019-03-20  Devin Rousso  <drousso@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r242910 r243246  
    9090}
    9191   
    92 JSString* errorDescriptionForValue(ExecState* exec, JSValue v)
    93 {
    94     if (v.isString())
    95         return jsNontrivialString(exec, makeString('"', asString(v)->value(exec), '"'));
     92String errorDescriptionForValue(ExecState* exec, JSValue v)
     93{
     94    if (v.isString()) {
     95        String string = asString(v)->value(exec);
     96        if (!string)
     97            return string;
     98        return tryMakeString('"', string, '"');
     99    }
     100
    96101    if (v.isSymbol())
    97         return jsNontrivialString(exec, asSymbol(v)->descriptiveString());
     102        return asSymbol(v)->descriptiveString();
    98103    if (v.isObject()) {
    99104        VM& vm = exec->vm();
     
    101106        JSObject* object = asObject(v);
    102107        if (object->methodTable(vm)->getCallData(object, callData) != CallType::None)
    103             return vm.smallStrings.functionString();
    104         return jsString(exec, JSObject::calculatedClassName(object));
    105     }
    106     return v.toString(exec);
     108            return vm.smallStrings.functionString()->value(exec);
     109        return JSObject::calculatedClassName(object);
     110    }
     111    return v.toString(exec)->value(exec);
    107112}
    108113   
     
    270275    auto scope = DECLARE_CATCH_SCOPE(vm);
    271276
    272     String errorMessage = tryMakeString(errorDescriptionForValue(exec, value)->value(exec), ' ', message);
    273     if (errorMessage.isNull())
     277    String valueDescription = errorDescriptionForValue(exec, value);
     278    if (!valueDescription)
     279        return createOutOfMemoryError(exec);
     280    String errorMessage = tryMakeString(valueDescription, ' ', message);
     281    if (!errorMessage)
    274282        return createOutOfMemoryError(exec);
    275283    scope.assertNoException();
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.h

    r242596 r243246  
    5555JSObject* createNotAFunctionError(ExecState*, JSValue);
    5656JSObject* createErrorForInvalidGlobalAssignment(ExecState*, const String&);
    57 JSString* errorDescriptionForValue(ExecState*, JSValue);
     57String errorDescriptionForValue(ExecState*, JSValue);
    5858
    5959JS_EXPORT_PRIVATE Exception* throwOutOfMemoryError(ExecState*, ThrowScope&);
Note: See TracChangeset for help on using the changeset viewer.