<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>184335</bug_id>
          
          <creation_ts>2018-04-05 11:11:21 -0700</creation_ts>
          <short_desc>Add necessary colon to CFNetwork selector</short_desc>
          <delta_ts>2018-04-09 16:39:36 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=184433</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="John Wilander">wilander</reporter>
          <assigned_to name="John Wilander">wilander</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>commit-queue</cc>
    
    <cc>darin</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1412110</commentid>
    <comment_count>0</comment_count>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-05 11:11:21 -0700</bug_when>
    <thetext>There needs to be a colon in the CFNetwork selector we&apos;re testing for if the selector takes a parameter.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412111</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-04-05 11:11:57 -0700</bug_when>
    <thetext>&lt;rdar://problem/39213124&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412113</commentid>
    <comment_count>2</comment_count>
      <attachid>337280</attachid>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-05 11:17:40 -0700</bug_when>
    <thetext>Created attachment 337280
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412141</commentid>
    <comment_count>3</comment_count>
      <attachid>337280</attachid>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-05 12:35:09 -0700</bug_when>
    <thetext>Comment on attachment 337280
Patch

Mac-WK2 build successful.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412142</commentid>
    <comment_count>4</comment_count>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-05 12:35:23 -0700</bug_when>
    <thetext>Thanks for the review, Brent!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412149</commentid>
    <comment_count>5</comment_count>
      <attachid>337280</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-04-05 13:02:24 -0700</bug_when>
    <thetext>Comment on attachment 337280
Patch

Clearing flags on attachment: 337280

Committed r230311: &lt;https://trac.webkit.org/changeset/230311&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412150</commentid>
    <comment_count>6</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2018-04-05 13:02:25 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412736</commentid>
    <comment_count>7</comment_count>
      <attachid>337280</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-04-08 10:36:28 -0700</bug_when>
    <thetext>Comment on attachment 337280
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=337280&amp;action=review

&gt; Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h:350
&gt; +    if ([request respondsToSelector:@selector(_setIgnoreHSTS:)])
&gt; +        [request performSelector:@selector(_setIgnoreHSTS:) withObject:[NSNumber numberWithBool:ignoreHSTS]];

This code is absolutely *not* correct. It is passing an object to a function that takes a boolean. I will provide a correct example shortly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412737</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-04-08 10:55:57 -0700</bug_when>
    <thetext>There are three problems with these HSTS functions:

1) These functions do not belong in the CFNetworkSPI.h, since they are not CFNetwork SPI, but rather convenience functions to make it easy to call the SPI. That’s not what should be in our SPI.h headers.

2) Two of the functions use the performSelector: return value incorrectly. The performSelector: method&apos;s return value only works if the return type is an object, or technically if it’s some non-object pointer type or if the return value is ignored. It is *not* correct to use if the return type is BOOL.

3) One of the functions uses performSelector:withObject: to pass an argument that is not an. Passing an NSNumber when the function takes a boolean won’t work properly; part of the NSNumber pointer is likely to be interpreted as the BOOL.

There are multiple correct ways to do this, none of which involve the performSelector: methods. One is to simply use the methods declared in the CFNetworkSPI.h header and be careful only to call if if the method is implemented. That’s probably the preferred one and easiest to get right. Another is to use &lt;wtf/ObjcRuntimeExtras.h&gt;, which contains correct alternatives to performSelector: for cases like these. A third is to use NSInvocation, which requires passing in the method signature.

Here is a sketch of the the first solution, leaving the code in a style suitable for a header (although I don’t think it should be in a header, and certainly not in CFNetworkSPI.h):

static bool schemeWasUpgradedDueToDynamicHSTS(NSURLRequest *request)
{
#if !USE(CFNETWORK_IGNORE_HSTS)
   UNUSED_PARAM(request);
   return false;
#else
   return [request respondsToSelector:@selector(_schemeWasUpgradedDueToDynamicHSTS)]
       &amp;&amp; [request _schemeWasUpgradedDueToDynamicHSTS];
#endif
}

static void setIgnoreHSTS(NSMutableURLRequest *request, bool ignoreHSTS)
{
#if !USE(CFNETWORK_IGNORE_HSTS)
   UNUSED_PARAM(request);
#else
    if ([request respondsToSelector:@selector(_setIgnoreHSTS:)])
        [request _setIgnoreHSTS:ignoreHSTS];
#endif
}

static bool ignoreHSTS(NSURLRequest *request)
{
#if !USE(CFNETWORK_IGNORE_HSTS)
   UNUSED(request);
   return false;
#else
   return [request respondsToSelector:@selector(_ignoreHSTS)]
       &amp;&amp; [request _ignoreHSTS];
#endif
}

I suggest filing a new bug and dealing with these issues.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412738</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-04-08 10:58:37 -0700</bug_when>
    <thetext>The ObjcRuntimeExtras.h versions would look something like this:

static bool schemeWasUpgradedDueToDynamicHSTS(NSURLRequest *request)
{
   return [request respondsToSelector:@selector(_schemeWasUpgradedDueToDynamicHSTS)]
       &amp;&amp; wtfObjcMsgSend&lt;BOOL&gt;(request, @selector(_schemeWasUpgradedDueToDynamicHSTS));
}

static void setIgnoreHSTS(NSMutableURLRequest *request, bool ignoreHSTS)
{
    BOOL ignoreHSTSArgument = ignoreHSTS; // Must be BOOL instead of bool.
    if ([request respondsToSelector:@selector(_setIgnoreHSTS:)])
        wtfObjcMsgSend&lt;void&gt;(request, @selector(_setIgnoreHSTS:), ignoreHSTSArgument);
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412739</commentid>
    <comment_count>10</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-04-08 11:02:24 -0700</bug_when>
    <thetext>Testing will show what does and does not work in practice. I suspect that the current argument problem in the current setIgnoreHSTS function without my suggested fix always sets the flag to true, but there is a chance it might behave differently on different architectures (ARM vs. Intel, 32-bit vs. 64-bit). The return value part might behave correctly by accident on some architectures, and incorrectly on others. Or might be harmless everywhere although incorrect; not sure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1412906</commentid>
    <comment_count>11</comment_count>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-09 10:00:09 -0700</bug_when>
    <thetext>Thanks for your comments, Darin. I will look into them today, including further tests of the existing code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413074</commentid>
    <comment_count>12</comment_count>
    <who name="John Wilander">wilander</who>
    <bug_when>2018-04-09 16:39:36 -0700</bug_when>
    <thetext>Follow-up work tracked in https://bugs.webkit.org/show_bug.cgi?id=184433.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>337280</attachid>
            <date>2018-04-05 11:17:40 -0700</date>
            <delta_ts>2018-04-05 13:02:24 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-184335-20180405111739.patch</filename>
            <type>text/plain</type>
            <size>1512</size>
            <attacher name="John Wilander">wilander</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL1BBTC9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291cmNl
L1dlYkNvcmUvUEFML0NoYW5nZUxvZwkocmV2aXNpb24gMjMwMzA4KQorKysgU291cmNlL1dlYkNv
cmUvUEFML0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE0IEBACisyMDE4LTA0
LTA1ICBKb2huIFdpbGFuZGVyICA8d2lsYW5kZXJAYXBwbGUuY29tPgorCisgICAgICAgIEFkZCBu
ZWNlc3NhcnkgY29sb24gdG8gQ0ZOZXR3b3JrIHNlbGVjdG9yCisgICAgICAgIGh0dHBzOi8vYnVn
cy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xODQzMzUKKyAgICAgICAgPHJkYXI6Ly9wcm9i
bGVtLzM5MjEzMTI0PgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisg
ICAgICAgICogcGFsL3NwaS9jZi9DRk5ldHdvcmtTUEkuaDoKKyAgICAgICAgKHNldElnbm9yZUhT
VFMpOgorCiAyMDE4LTA0LTA0ICBQZXIgQXJuZSBWb2xsYW4gIDxwdm9sbGFuQGFwcGxlLmNvbT4K
IAogICAgICAgICBUaGUgbG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