Title: [136817] trunk/Source/WebCore
Revision
136817
Author
[email protected]
Date
2012-12-06 00:50:56 -0800 (Thu, 06 Dec 2012)

Log Message

[JSC] Check whether property is an array before attempting conversion to array in JSDictionary
https://bugs.webkit.org/show_bug.cgi?id=96614

Patch by Michael Pruett <[email protected]> on 2012-12-06
Reviewed by Kentaro Hara.

JSDictionary should check whether the property being accessed in get()
is an array before attempting to convert the value to an array.

Previously calling get() with a result type of Vector<String> when
the named property could not be converted to an array would generate
an exception.

Tests: storage/indexeddb/*

* bindings/js/JSDictionary.cpp:
(WebCore::JSDictionary::convertValue):
* bindings/js/JSDictionary.h:
(WebCore::JSDictionary::tryGetPropertyAndResult):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136816 => 136817)


--- trunk/Source/WebCore/ChangeLog	2012-12-06 08:47:18 UTC (rev 136816)
+++ trunk/Source/WebCore/ChangeLog	2012-12-06 08:50:56 UTC (rev 136817)
@@ -1,3 +1,24 @@
+2012-12-06  Michael Pruett  <[email protected]>
+
+        [JSC] Check whether property is an array before attempting conversion to array in JSDictionary
+        https://bugs.webkit.org/show_bug.cgi?id=96614
+
+        Reviewed by Kentaro Hara.
+
+        JSDictionary should check whether the property being accessed in get()
+        is an array before attempting to convert the value to an array.
+
+        Previously calling get() with a result type of Vector<String> when
+        the named property could not be converted to an array would generate
+        an exception.
+
+        Tests: storage/indexeddb/*
+
+        * bindings/js/JSDictionary.cpp:
+        (WebCore::JSDictionary::convertValue):
+        * bindings/js/JSDictionary.h:
+        (WebCore::JSDictionary::tryGetPropertyAndResult):
+
 2012-12-05  Kentaro Hara  <[email protected]>
 
         [V8] Pass Isolate to toDOMStringList()

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.cpp (136816 => 136817)


--- trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2012-12-06 08:47:18 UTC (rev 136816)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.cpp	2012-12-06 08:50:56 UTC (rev 136817)
@@ -68,152 +68,182 @@
     return PropertyFound;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, bool& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, bool& result)
 {
     result = value.toBoolean(exec);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, int& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, int& result)
 {
     result = value.toInt32(exec);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned& result)
 {
     result = value.toUInt32(exec);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned short& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned short& result)
 {
     result = static_cast<unsigned short>(value.toUInt32(exec));
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned long& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned long& result)
 {
     result = static_cast<unsigned long>(value.toUInt32(exec));
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned long long& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, unsigned long long& result)
 {
     double d = value.toNumber(exec);
     doubleToInteger(d, result);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, double& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, double& result)
 {
     result = value.toNumber(exec);
+    return true;
 }
 
-void JSDictionary::convertValue(JSC::ExecState* exec, JSC::JSValue value, Dictionary& result)
+bool JSDictionary::convertValue(JSC::ExecState* exec, JSC::JSValue value, Dictionary& result)
 {
     result = Dictionary(exec, value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, String& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, String& result)
 {
     result = value.toString(exec)->value(exec);
+    return !exec->hadException();
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, Vector<String>& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, Vector<String>& result)
 {
     if (value.isUndefinedOrNull())
-        return;
+        return false;
 
+    if (!value.isObject())
+        return false;
+    JSObject* object = asObject(value);
+    if (!isJSArray(object) && !object->inherits(&JSArray::s_info))
+        return false;
+
     unsigned length = 0;
-    JSObject* object = toJSSequence(exec, value, length);
+    object = toJSSequence(exec, value, length);
     if (exec->hadException())
-        return;
+        return false;
 
     for (unsigned i = 0 ; i < length; ++i) {
         JSValue itemValue = object->get(exec, i);
         if (exec->hadException())
-            return;
+            return false;
         result.append(itemValue.toString(exec)->value(exec));
     }
+
+    return !exec->hadException();
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, ScriptValue& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, ScriptValue& result)
 {
     result = ScriptValue(exec->globalData(), value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, RefPtr<SerializedScriptValue>& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, RefPtr<SerializedScriptValue>& result)
 {
     result = SerializedScriptValue::create(exec, value, 0, 0);
+    return !exec->hadException();
 }
 
-void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<DOMWindow>& result)
+bool JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<DOMWindow>& result)
 {
     result = toDOMWindow(value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<EventTarget>& result)
+bool JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<EventTarget>& result)
 {
     result = toEventTarget(value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Node>& result)
+bool JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Node>& result)
 {
     result = toNode(value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Storage>& result)
+bool JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<Storage>& result)
 {
     result = toStorage(value);
+    return true;
 }
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, MessagePortArray& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, MessagePortArray& result)
 {
     ArrayBufferArray arrayBuffers;
     fillMessagePortArray(exec, value, result, arrayBuffers);
+    return true;
 }
 
 #if ENABLE(VIDEO_TRACK)
-void JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<TrackBase>& result)
+bool JSDictionary::convertValue(ExecState*, JSValue value, RefPtr<TrackBase>& result)
 {
     result = toTrack(value);
+    return true;
 }
 #endif
 
 #if ENABLE(MUTATION_OBSERVERS) || ENABLE(WEB_INTENTS)
-void JSDictionary::convertValue(ExecState* exec, JSValue value, HashSet<AtomicString>& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, HashSet<AtomicString>& result)
 {
     result.clear();
 
     if (value.isUndefinedOrNull())
-        return;
+        return false;
 
     unsigned length = 0;
     JSObject* object = toJSSequence(exec, value, length);
     if (exec->hadException())
-        return;
+        return false;
 
     for (unsigned i = 0 ; i < length; ++i) {
         JSValue itemValue = object->get(exec, i);
         if (exec->hadException())
-            return;
+            return false;
         result.add(itemValue.toString(exec)->value(exec));
     }
+
+    return !exec->hadException();
 }
 #endif
 
-void JSDictionary::convertValue(ExecState* exec, JSValue value, ArrayValue& result)
+bool JSDictionary::convertValue(ExecState* exec, JSValue value, ArrayValue& result)
 {
     if (value.isUndefinedOrNull())
-        return;
+        return false;
 
     result = ArrayValue(exec, value);
+    return true;
 }
 
-void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<Uint8Array>& result)
+bool JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<Uint8Array>& result)
 {
     result = toUint8Array(value);
+    return true;
 }
 
 #if ENABLE(ENCRYPTED_MEDIA)
-void JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<MediaKeyError>& result)
+bool JSDictionary::convertValue(JSC::ExecState*, JSC::JSValue value, RefPtr<MediaKeyError>& result)
 {
     result = toMediaKeyError(value);
+    return true;
 }
 #endif
 

Modified: trunk/Source/WebCore/bindings/js/JSDictionary.h (136816 => 136817)


--- trunk/Source/WebCore/bindings/js/JSDictionary.h	2012-12-06 08:47:18 UTC (rev 136816)
+++ trunk/Source/WebCore/bindings/js/JSDictionary.h	2012-12-06 08:50:56 UTC (rev 136817)
@@ -81,40 +81,41 @@
     enum GetPropertyResult {
         ExceptionThrown,
         NoPropertyFound,
-        PropertyFound
+        PropertyFound,
+        ConversionFailed
     };
     
     template <typename T, typename Result>
     GetPropertyResult tryGetPropertyAndResult(const char* propertyName, T* context, void (*setter)(T* context, const Result&)) const;
     GetPropertyResult tryGetProperty(const char* propertyName, JSC::JSValue&) const;
 
-    static void convertValue(JSC::ExecState*, JSC::JSValue, bool& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, int& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned short& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned long& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, unsigned long long& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, double& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, Dictionary& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, String& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, ScriptValue& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, Vector<String>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<SerializedScriptValue>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<DOMWindow>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<EventTarget>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Node>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Storage>& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, MessagePortArray& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, bool& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, int& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, unsigned& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, unsigned short& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, unsigned long& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, unsigned long long& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, double& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, Dictionary& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, String& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, ScriptValue& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, Vector<String>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<SerializedScriptValue>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<DOMWindow>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<EventTarget>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Node>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Storage>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, MessagePortArray& result);
 #if ENABLE(VIDEO_TRACK)
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<TrackBase>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<TrackBase>& result);
 #endif
 #if ENABLE(MUTATION_OBSERVERS) || ENABLE(WEB_INTENTS)
-    static void convertValue(JSC::ExecState*, JSC::JSValue, HashSet<AtomicString>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, HashSet<AtomicString>& result);
 #endif
-    static void convertValue(JSC::ExecState*, JSC::JSValue, ArrayValue& result);
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Uint8Array>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, ArrayValue& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<Uint8Array>& result);
 #if ENABLE(ENCRYPTED_MEDIA)
-    static void convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<MediaKeyError>& result);
+    static bool convertValue(JSC::ExecState*, JSC::JSValue, RefPtr<MediaKeyError>& result);
 #endif
 
     JSC::ExecState* m_exec;
@@ -149,16 +150,20 @@
         return getPropertyResult;
     case PropertyFound: {
         Result result;
-        convertValue(m_exec, value, result);
+        if (!convertValue(m_exec, value, result)) {
+            if (m_exec->hadException())
+                return ExceptionThrown;
+            return ConversionFailed;
+        }
 
-        if (m_exec->hadException())
-            return ExceptionThrown;
-
         setter(context, result);
         break;
     }
     case NoPropertyFound:
         break;
+    case ConversionFailed:
+        ASSERT_NOT_REACHED();
+        break;
     }
 
     return getPropertyResult;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to