Title: [272450] trunk/Source/WebKit
Revision
272450
Author
[email protected]
Date
2021-02-05 16:16:20 -0800 (Fri, 05 Feb 2021)

Log Message

Add missing null checks to decoding functions involving RetainPtr
https://bugs.webkit.org/show_bug.cgi?id=221441

Reviewed by Anders Carlsson.

* Shared/mac/WebCoreArgumentCodersMac.mm:
(IPC::ArgumentCoder<WebCore::ResourceRequest>::decodePlatformData): Fail if the dictionary
is null: the encoder never encodes a null dictionary.
(IPC::ArgumentCoder<WebCore::CertificateInfo>::decode): Fail if the SecTrustRef is null:
the encoder never encodes a null SecTrustRef. Fail if the certificate chain array is null:
the encoder never encodes a null CFArrayRef.
(IPC::decodeNSError): Return a RetainPtr instead of using a bool return value and a
RetainPtr out argument. Fail if the user info dictionary is null: the encoder never encodes
a null user info dictionary.
(IPC::ArgumentCoder<WebCore::ResourceError>::decodePlatformData): Updated for the change
to the interface of decodeNSError.
(IPC::ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode): Fail if the CFDataRef
is null: the encoder never encodes a null CFDataRef.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (272449 => 272450)


--- trunk/Source/WebKit/ChangeLog	2021-02-06 00:07:17 UTC (rev 272449)
+++ trunk/Source/WebKit/ChangeLog	2021-02-06 00:16:20 UTC (rev 272450)
@@ -1,3 +1,24 @@
+2021-02-05  Darin Adler  <[email protected]>
+
+        Add missing null checks to decoding functions involving RetainPtr
+        https://bugs.webkit.org/show_bug.cgi?id=221441
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/mac/WebCoreArgumentCodersMac.mm:
+        (IPC::ArgumentCoder<WebCore::ResourceRequest>::decodePlatformData): Fail if the dictionary
+        is null: the encoder never encodes a null dictionary.
+        (IPC::ArgumentCoder<WebCore::CertificateInfo>::decode): Fail if the SecTrustRef is null:
+        the encoder never encodes a null SecTrustRef. Fail if the certificate chain array is null:
+        the encoder never encodes a null CFArrayRef.
+        (IPC::decodeNSError): Return a RetainPtr instead of using a bool return value and a
+        RetainPtr out argument. Fail if the user info dictionary is null: the encoder never encodes
+        a null user info dictionary.
+        (IPC::ArgumentCoder<WebCore::ResourceError>::decodePlatformData): Updated for the change
+        to the interface of decodeNSError.
+        (IPC::ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode): Fail if the CFDataRef
+        is null: the encoder never encodes a null CFDataRef.
+
 2021-02-05  Brent Fulgham  <[email protected]>
 
         REGRESSION (r271815): [macOS] /dev/dtracehelper is blocked on customer builds, even with SIP disabled

Modified: trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm (272449 => 272450)


--- trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2021-02-06 00:07:17 UTC (rev 272449)
+++ trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2021-02-06 00:16:20 UTC (rev 272450)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2013 Company 100 Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,6 @@
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 #import <WebCore/MediaPlaybackTargetContext.h>
 #import <objc/runtime.h>
-
 #import <pal/cocoa/AVFoundationSoftLink.h>
 #endif
 
@@ -188,7 +187,7 @@
     
     return adoptNS([[NSURLRequest alloc] _initWithCFURLRequest:cfRequest.get()]);
 }
-    
+
 void ArgumentCoder<WebCore::ResourceRequest>::encodePlatformData(Encoder& encoder, const WebCore::ResourceRequest& resourceRequest)
 {
     RetainPtr<NSURLRequest> requestToSerialize = resourceRequest.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
@@ -228,12 +227,9 @@
     }
 
     RetainPtr<CFDictionaryRef> dictionary;
-    if (!IPC::decode(decoder, dictionary))
+    if (!IPC::decode(decoder, dictionary) || !dictionary)
         return false;
 
-    if (!dictionary)
-        return false;
-
     auto nsURLRequest = createNSURLRequestFromSerializableRepresentation(dictionary.get(), IPC::tokenNullptrTypeRef());
     if (!nsURLRequest)
         return false;
@@ -292,7 +288,7 @@
 #if HAVE(SEC_TRUST_SERIALIZATION)
     case WebCore::CertificateInfo::Type::Trust: {
         RetainPtr<SecTrustRef> trust;
-        if (!IPC::decode(decoder, trust))
+        if (!IPC::decode(decoder, trust) || !trust)
             return false;
 
         certificateInfo = WebCore::CertificateInfo(WTFMove(trust));
@@ -301,7 +297,7 @@
 #endif
     case WebCore::CertificateInfo::Type::CertificateChain: {
         RetainPtr<CFArrayRef> certificateChain;
-        if (!IPC::decode(decoder, certificateChain))
+        if (!IPC::decode(decoder, certificateChain) || !certificateChain)
             return false;
 
         certificateInfo = WebCore::CertificateInfo(WTFMove(certificateChain));
@@ -397,28 +393,28 @@
     encodeNSError(encoder, resourceError.nsError());
 }
 
-static WARN_UNUSED_RETURN bool decodeNSError(Decoder& decoder, RetainPtr<NSError>& nsError)
+static RetainPtr<NSError> decodeNSError(Decoder& decoder)
 {
     String domain;
     if (!decoder.decode(domain))
-        return false;
+        return nil;
 
     int64_t code;
     if (!decoder.decode(code))
-        return false;
+        return nil;
 
     RetainPtr<CFDictionaryRef> userInfo;
-    if (!IPC::decode(decoder, userInfo))
-        return false;
+    if (!IPC::decode(decoder, userInfo) || !userInfo)
+        return nil;
 
     bool hasUnderlyingError = false;
     if (!decoder.decode(hasUnderlyingError))
-        return false;
+        return nil;
 
     if (hasUnderlyingError) {
-        RetainPtr<NSError> underlyingNSError;
-        if (!decodeNSError(decoder, underlyingNSError))
-            return false;
+        auto underlyingNSError = decodeNSError(decoder);
+        if (!underlyingNSError)
+            return nil;
 
         auto mutableUserInfo = adoptCF(CFDictionaryCreateMutableCopy(kCFAllocatorDefault, CFDictionaryGetCount(userInfo.get()) + 1, userInfo.get()));
         CFDictionarySetValue(mutableUserInfo.get(), (__bridge CFStringRef)NSUnderlyingErrorKey, (__bridge CFTypeRef)underlyingNSError.get());
@@ -425,14 +421,13 @@
         userInfo = WTFMove(mutableUserInfo);
     }
 
-    nsError = adoptNS([[NSError alloc] initWithDomain:domain code:code userInfo:(__bridge NSDictionary *)userInfo.get()]);
-    return true;
+    return adoptNS([[NSError alloc] initWithDomain:domain code:code userInfo:(__bridge NSDictionary *)userInfo.get()]);
 }
 
 bool ArgumentCoder<WebCore::ResourceError>::decodePlatformData(Decoder& decoder, WebCore::ResourceError& resourceError)
 {
-    RetainPtr<NSError> nsError;
-    if (!decodeNSError(decoder, nsError))
+    auto nsError = decodeNSError(decoder);
+    if (!nsError)
         return false;
 
     resourceError = WebCore::ResourceError(nsError.get());
@@ -600,7 +595,7 @@
 bool ArgumentCoder<WebCore::ContentFilterUnblockHandler>::decode(Decoder& decoder, WebCore::ContentFilterUnblockHandler& contentFilterUnblockHandler)
 {
     RetainPtr<CFDataRef> data;
-    if (!IPC::decode(decoder, data))
+    if (!IPC::decode(decoder, data) || !data)
         return false;
 
     auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:(__bridge NSData *)data.get() error:nullptr]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to