Title: [185683] trunk
Revision
185683
Author
achristen...@apple.com
Date
2015-06-17 17:51:37 -0700 (Wed, 17 Jun 2015)

Log Message

[Content Extensions] Fail to parse invalid arrays
https://bugs.webkit.org/show_bug.cgi?id=146079
rdar://problem/21422649

Reviewed by Benjamin Poulain.

Source/WebCore:

Covered by new and corrected API tests.

* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::loadTrigger):
Fail to parse invalid arrays for if-domain, unless-domain, resource-type, and load-type arrays.

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F):
Correct and add parsing tests with invalid arrays.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185682 => 185683)


--- trunk/Source/WebCore/ChangeLog	2015-06-18 00:49:54 UTC (rev 185682)
+++ trunk/Source/WebCore/ChangeLog	2015-06-18 00:51:37 UTC (rev 185683)
@@ -1,3 +1,17 @@
+2015-06-17  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Fail to parse invalid arrays
+        https://bugs.webkit.org/show_bug.cgi?id=146079
+        rdar://problem/21422649
+
+        Reviewed by Benjamin Poulain.
+
+        Covered by new and corrected API tests.
+
+        * contentextensions/ContentExtensionParser.cpp:
+        (WebCore::ContentExtensions::loadTrigger):
+        Fail to parse invalid arrays for if-domain, unless-domain, resource-type, and load-type arrays.
+
 2015-06-16  Jon Honeycutt  <jhoneyc...@apple.com>
 
         Position::findParent() should take a reference

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (185682 => 185683)


--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-06-18 00:49:54 UTC (rev 185682)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-06-18 00:51:37 UTC (rev 185683)
@@ -131,18 +131,20 @@
         trigger.urlFilterIsCaseSensitive = urlFilterCaseValue.toBoolean(&exec);
 
     JSValue resourceTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "resource-type"));
-    if (resourceTypeValue && !exec.hadException()) {
+    if (!exec.hadException() && resourceTypeValue.isObject()) {
         auto typeFlagsError = getTypeFlags(exec, resourceTypeValue, trigger.flags, readResourceType);
         if (typeFlagsError)
             return typeFlagsError;
-    }
+    } else if (!resourceTypeValue.isUndefined())
+        return ContentExtensionError::JSONInvalidTriggerFlagsArray;
 
     JSValue loadTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "load-type"));
-    if (loadTypeValue && !exec.hadException()) {
+    if (!exec.hadException() && loadTypeValue.isObject()) {
         auto typeFlagsError = getTypeFlags(exec, loadTypeValue, trigger.flags, readLoadType);
         if (typeFlagsError)
             return typeFlagsError;
-    }
+    } else if (!loadTypeValue.isUndefined())
+        return ContentExtensionError::JSONInvalidTriggerFlagsArray;
 
     JSValue ifDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "if-domain"));
     if (!exec.hadException() && ifDomain.isObject()) {
@@ -153,7 +155,8 @@
             return ContentExtensionError::JSONInvalidDomainList;
         ASSERT(trigger.domainCondition == Trigger::DomainCondition::None);
         trigger.domainCondition = Trigger::DomainCondition::IfDomain;
-    }
+    } else if (!ifDomain.isUndefined())
+        return ContentExtensionError::JSONInvalidDomainList;
     
     JSValue unlessDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "unless-domain"));
     if (!exec.hadException() && unlessDomain.isObject()) {
@@ -165,7 +168,8 @@
         if (trigger.domains.isEmpty())
             return ContentExtensionError::JSONInvalidDomainList;
         trigger.domainCondition = Trigger::DomainCondition::UnlessDomain;
-    }
+    } else if (!unlessDomain.isUndefined())
+        return ContentExtensionError::JSONInvalidDomainList;
 
     return { };
 }

Modified: trunk/Tools/ChangeLog (185682 => 185683)


--- trunk/Tools/ChangeLog	2015-06-18 00:49:54 UTC (rev 185682)
+++ trunk/Tools/ChangeLog	2015-06-18 00:51:37 UTC (rev 185683)
@@ -1,3 +1,15 @@
+2015-06-17  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Fail to parse invalid arrays
+        https://bugs.webkit.org/show_bug.cgi?id=146079
+        rdar://problem/21422649
+
+        Reviewed by Benjamin Poulain.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::TEST_F):
+        Correct and add parsing tests with invalid arrays.
+
 2015-06-17  Matt Rajca  <mra...@apple.com>
 
         Unreviewed. Added myself as a committer.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (185682 => 185683)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-06-18 00:49:54 UTC (rev 185682)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-06-18 00:51:37 UTC (rev 185683)
@@ -805,12 +805,28 @@
         ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":[5]}}]",
         ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":5}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":\"first-party\"}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":null}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":false}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":{}}}]",
         ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":[\"invalid\"]}}]",
         ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":[5]}}]",
         ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":5}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":\"document\"}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":null}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":false}}]",
+        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     
     StringBuilder rules;
     rules.append("[");
@@ -826,9 +842,15 @@
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"]}}]", { });
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"A\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\\u00DC\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"0\"]}}]", { });
@@ -836,9 +858,9 @@
 
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[],\"unless-domain\":[\"a\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", { });
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", { });
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", { });
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONUnlessAndIfDomain);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to