Title: [264780] trunk/Source
Revision
264780
Author
ddkil...@apple.com
Date
2020-07-23 11:45:58 -0700 (Thu, 23 Jul 2020)

Log Message

[IPC hardening] WebKit::ArgumentCoder<BlobPart>::decode() and encode() should use enum BlobPart::Type
<https://webkit.org/b/214665>
<rdar://problem/65777948>

Reviewed by Darin Adler.

Source/WebCore:

* platform/network/BlobPart.h:
(WebCore::BlobPart::Type):
- Convert to an enum class of size `bool`.
(WebCore::BlobPart::BlobPart):
(WebCore::BlobPart::data const):
(WebCore::BlobPart::moveData):
(WebCore::BlobPart::url const):
- Change BlobPart::Type enums to use fully qualified name.
* platform/network/BlobRegistryImpl.cpp:
(WebCore::BlobRegistryImpl::registerBlobURL):
- Change BlobPart::Type enums to use fully qualified name.

Source/WebKit:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<BlobPart>::encode):
- Change BlobPart::Type enums to use fully qualified name.
- Encode using WebCore::BlobPart::Type value.
- Change break statements to early return statements.
- Add ASSERT_NOT_REACHED() to catch bugs.
(IPC::ArgumentCoder<BlobPart>::decode):
- Change BlobPart::Type enums to use fully qualified name.
- Decode using Optional<WebCore::BlobPart::Type> variable.
- Change break statements to early return statements.
- Remove default: label, move `return WTF::nullopt` to the end
  of the method, and add ASSERT_NOT_REACHED() to catch bugs.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264779 => 264780)


--- trunk/Source/WebCore/ChangeLog	2020-07-23 18:26:14 UTC (rev 264779)
+++ trunk/Source/WebCore/ChangeLog	2020-07-23 18:45:58 UTC (rev 264780)
@@ -1,3 +1,23 @@
+2020-07-23  David Kilzer  <ddkil...@apple.com>
+
+        [IPC hardening] WebKit::ArgumentCoder<BlobPart>::decode() and encode() should use enum BlobPart::Type
+        <https://webkit.org/b/214665>
+        <rdar://problem/65777948>
+
+        Reviewed by Darin Adler.
+
+        * platform/network/BlobPart.h:
+        (WebCore::BlobPart::Type):
+        - Convert to an enum class of size `bool`.
+        (WebCore::BlobPart::BlobPart):
+        (WebCore::BlobPart::data const):
+        (WebCore::BlobPart::moveData):
+        (WebCore::BlobPart::url const):
+        - Change BlobPart::Type enums to use fully qualified name.
+        * platform/network/BlobRegistryImpl.cpp:
+        (WebCore::BlobRegistryImpl::registerBlobURL):
+        - Change BlobPart::Type enums to use fully qualified name.
+
 2020-07-23  Simon Fraser  <simon.fra...@apple.com>
 
         updateRendering trace point should exclude SVG

Modified: trunk/Source/WebCore/platform/network/BlobPart.h (264779 => 264780)


--- trunk/Source/WebCore/platform/network/BlobPart.h	2020-07-23 18:26:14 UTC (rev 264779)
+++ trunk/Source/WebCore/platform/network/BlobPart.h	2020-07-23 18:45:58 UTC (rev 264780)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -31,24 +31,24 @@
 
 class BlobPart {
 public:
-    enum Type {
+    enum class Type : bool {
         Data,
         Blob
     };
 
     BlobPart()
-        : m_type(Data)
+        : m_type(Type::Data)
     {
     }
 
     BlobPart(Vector<uint8_t>&& data)
-        : m_type(Data)
+        : m_type(Type::Data)
         , m_data(WTFMove(data))
     {
     }
 
     BlobPart(const URL& url)
-        : m_type(Blob)
+        : m_type(Type::Blob)
         , m_url(url)
     {
     }
@@ -57,19 +57,19 @@
 
     const Vector<uint8_t>& data() const
     {
-        ASSERT(m_type == Data);
+        ASSERT(m_type == Type::Data);
         return m_data;
     }
 
     Vector<uint8_t> moveData()
     {
-        ASSERT(m_type == Data);
+        ASSERT(m_type == Type::Data);
         return WTFMove(m_data);
     }
 
     const URL& url() const
     {
-        ASSERT(m_type == Blob);
+        ASSERT(m_type == Type::Blob);
         return m_url;
     }
 
@@ -84,4 +84,4 @@
     URL m_url;
 };
 
-}
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp (264779 => 264780)


--- trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp	2020-07-23 18:26:14 UTC (rev 264779)
+++ trunk/Source/WebCore/platform/network/BlobRegistryImpl.cpp	2020-07-23 18:45:58 UTC (rev 264780)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -134,13 +134,13 @@
 
     for (BlobPart& part : blobParts) {
         switch (part.type()) {
-        case BlobPart::Data: {
+        case BlobPart::Type::Data: {
             auto movedData = part.moveData();
             auto data = ""
             blobData->appendData(data);
             break;
         }
-        case BlobPart::Blob: {
+        case BlobPart::Type::Blob: {
             if (auto blob = m_blobs.get(part.url().string())) {
                 for (const BlobDataItem& item : blob->items())
                     blobData->m_items.append(item);

Modified: trunk/Source/WebKit/ChangeLog (264779 => 264780)


--- trunk/Source/WebKit/ChangeLog	2020-07-23 18:26:14 UTC (rev 264779)
+++ trunk/Source/WebKit/ChangeLog	2020-07-23 18:45:58 UTC (rev 264780)
@@ -1,5 +1,26 @@
 2020-07-23  David Kilzer  <ddkil...@apple.com>
 
+        [IPC hardening] WebKit::ArgumentCoder<BlobPart>::decode() and encode() should use enum BlobPart::Type
+        <https://webkit.org/b/214665>
+        <rdar://problem/65777948>
+
+        Reviewed by Darin Adler.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<BlobPart>::encode):
+        - Change BlobPart::Type enums to use fully qualified name.
+        - Encode using WebCore::BlobPart::Type value.
+        - Change break statements to early return statements.
+        - Add ASSERT_NOT_REACHED() to catch bugs.
+        (IPC::ArgumentCoder<BlobPart>::decode):
+        - Change BlobPart::Type enums to use fully qualified name.
+        - Decode using Optional<WebCore::BlobPart::Type> variable.
+        - Change break statements to early return statements.
+        - Remove default: label, move `return WTF::nullopt` to the end
+          of the method, and add ASSERT_NOT_REACHED() to catch bugs.
+
+2020-07-23  David Kilzer  <ddkil...@apple.com>
+
         [IPC hardening] FilterOperation decode/encode should use early returns
         <https://webkit.org/b/214667>
         <rdar://problem/65946400>

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (264779 => 264780)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-07-23 18:26:14 UTC (rev 264779)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-07-23 18:45:58 UTC (rev 264780)
@@ -2478,47 +2478,43 @@
 
 void ArgumentCoder<BlobPart>::encode(Encoder& encoder, const BlobPart& blobPart)
 {
-    encoder << static_cast<uint32_t>(blobPart.type());
+    encoder << blobPart.type();
     switch (blobPart.type()) {
-    case BlobPart::Data:
+    case BlobPart::Type::Data:
         encoder << blobPart.data();
-        break;
-    case BlobPart::Blob:
+        return;
+    case BlobPart::Type::Blob:
         encoder << blobPart.url();
-        break;
+        return;
     }
+    ASSERT_NOT_REACHED();
 }
 
 Optional<BlobPart> ArgumentCoder<BlobPart>::decode(Decoder& decoder)
 {
-    BlobPart blobPart;
-
-    Optional<uint32_t> type;
+    Optional<BlobPart::Type> type;
     decoder >> type;
     if (!type)
         return WTF::nullopt;
 
     switch (*type) {
-    case BlobPart::Data: {
+    case BlobPart::Type::Data: {
         Optional<Vector<uint8_t>> data;
         decoder >> data;
         if (!data)
             return WTF::nullopt;
-        blobPart = BlobPart(WTFMove(*data));
-        break;
+        return BlobPart(WTFMove(*data));
     }
-    case BlobPart::Blob: {
+    case BlobPart::Type::Blob: {
         URL url;
         if (!decoder.decode(url))
             return WTF::nullopt;
-        blobPart = BlobPart(url);
-        break;
+        return BlobPart(url);
     }
-    default:
-        return WTF::nullopt;
     }
 
-    return blobPart;
+    ASSERT_NOT_REACHED();
+    return WTF::nullopt;
 }
 
 void ArgumentCoder<TextIndicatorData>::encode(Encoder& encoder, const TextIndicatorData& textIndicatorData)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to