<?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>19287</bug_id>
          
          <creation_ts>2008-05-28 01:58:53 -0700</creation_ts>
          <short_desc>return value of malloc() is not checked in npruntime.cpp</short_desc>
          <delta_ts>2009-01-11 02:27:17 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Plug-ins</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Peter Siket">pepe</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>andersca</cc>
    
    <cc>ap</cc>
    
    <cc>darin</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>81702</commentid>
    <comment_count>0</comment_count>
    <who name="Peter Siket">pepe</who>
    <bug_when>2008-05-28 01:58:53 -0700</bug_when>
    <thetext>The return values of the following malloc invocations are not checked (rev. 34169):

WebKit/WebCore/bridge/npruntime.cpp(106):
106:             identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier));
107:             identifier-&gt;isString = false;
108:             identifier-&gt;value.number = intid;

WebKit/WebCore/bridge/npruntime.cpp(115):
115:             identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier));
116:             // We never release identifier names, so this dictionary will grow.
117:             identifier-&gt;isString = false;
118:             identifier-&gt;value.number = intid;

WebKit/WebCore/bridge/npruntime.cpp(153)
153:     variant-&gt;value.stringValue.UTF8Characters = (NPUTF8 *)malloc(sizeof(NPUTF8) * value-&gt;UTF8Length);
154:     memcpy((void*)variant-&gt;value.stringValue.UTF8Characters, value-&gt;UTF8Characters, sizeof(NPUTF8) * value-&gt;UTF8Length);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81712</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-05-28 05:31:03 -0700</bug_when>
    <thetext>While technically true, I&apos;m not sure if we want to track this as a bug - this is a small allocation, so out of memory condition is unlikely to be ever hit in practice. Even if this happens, the application will just crash, without letting anyone write to random memory locations. Aborting is what we&apos;d likely have to do in an explicit check anyway.

See also: bug 18670.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81735</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-05-28 08:45:22 -0700</bug_when>
    <thetext>I&apos;d prefer this is duped against the &quot;malloc should crash instead of ever returning null&quot; bug.  But I&apos;m not sure all of the other webkit committers are in agreement w/ me on that one. :)

Confirming that not-checking a null-returning malloc is bad, yes. :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81739</commentid>
    <comment_count>3</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-05-28 08:59:04 -0700</bug_when>
    <thetext>I suggest we call new or fastMalloc here as we do in the rest of our code. I can&apos;t see any reason to use the system malloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100828</commentid>
    <comment_count>4</comment_count>
    <who name="Gabriella Toth">gtoth</who>
    <bug_when>2008-12-01 06:56:22 -0800</bug_when>
    <thetext>In wtf/Fastmalloc.cpp, the allocation is checked therefore we should check this here as well. We can use the same method here: if the allocation is unsuccessful, CRASH macro can be invoked.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100829</commentid>
    <comment_count>5</comment_count>
      <attachid>25630</attachid>
    <who name="Gabriella Toth">gtoth</who>
    <bug_when>2008-12-01 06:57:20 -0800</bug_when>
    <thetext>Created attachment 25630
proposed patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100837</commentid>
    <comment_count>6</comment_count>
      <attachid>25630</attachid>
    <who name="Anders Carlsson">andersca</who>
    <bug_when>2008-12-01 10:06:48 -0800</bug_when>
    <thetext>Comment on attachment 25630
proposed patch

I like Darin&apos;s suggestion better, if we use fastMalloc instead of malloc it should take care of crashing if the allocation fails.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100984</commentid>
    <comment_count>7</comment_count>
    <who name="Gabriella Toth">gtoth</who>
    <bug_when>2008-12-01 23:56:21 -0800</bug_when>
    <thetext>But according to another bug thread (bug #20566, comment #1) we should really call NPN_MemAlloc but it doesn&apos;t work on Mac. Because of this thread I didn&apos;t use fastmalloc here but I try to use its same functionality (CRASH).
Should fastmalloc be used here as well?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102556</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-12-15 06:20:39 -0800</bug_when>
    <thetext>(In reply to comment #7)
&gt; But according to another bug thread (bug #20566, comment #1) we should really
&gt; call NPN_MemAlloc but it doesn&apos;t work on Mac.

That NPN_MemAlloc comment in NP_jsobject.cpp is long-obsolete. That comment was written back when this code was in JavaScriptCore and NPN_MemAlloc was in WebKit. But now both the code and the NPN_MemAlloc function are in WebCore. So that issues is not an obstacle to using fastMalloc and fastFree here.

On the other hand, there might be a risk with plug-in compatibility, if plug-ins themselves accidentally mix malloc/free with NPN_MemAlloc and NPN_MemFree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102557</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-12-15 06:43:25 -0800</bug_when>
    <thetext>We want to avoid having to sprinkle CRASH calls all around the project, so if we can use fastMalloc or new that would be considerably more elegant.

For PrivateIdentifier, new would be just fine. There&apos;s no need to call malloc there.

For UTF8Characters I think we&apos;re stuck with malloc because, for example, I see code in testbindings.cpp setting UTF8Characters by calling strdup. I don&apos;t think we&apos;re free to use a malloc other than the system malloc in that case.

There are also invocations of strdup, and the issue of failure handling is no different for strdup than for malloc. I think I see at least one case where someone expects to use strdup to allocate and then the caller will free with either NPN_Free or free, so I think we can&apos;t change those to fastMalloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102558</commentid>
    <comment_count>10</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-12-15 07:07:00 -0800</bug_when>
    <thetext>(In reply to comment #8)
&gt; That NPN_MemAlloc comment in NP_jsobject.cpp is long-obsolete. That comment was
&gt; written back when this code was in JavaScriptCore and NPN_MemAlloc was in
&gt; WebKit. But now both the code and the NPN_MemAlloc function are in WebCore. So
&gt; that issues is not an obstacle to using fastMalloc and fastFree here.

I was wrong about that. The NPN_MemAlloc that is in WebCore is for non-Mac platforms. It&apos;s still true on the Mac.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102570</commentid>
    <comment_count>11</comment_count>
    <who name="Anders Carlsson">andersca</who>
    <bug_when>2008-12-15 10:52:53 -0800</bug_when>
    <thetext>(In reply to comment #10)
&gt; 
&gt; I was wrong about that. The NPN_MemAlloc that is in WebCore is for non-Mac
&gt; platforms. It&apos;s still true on the Mac.
&gt; 

We can still use FastMalloc from WebKit though, right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102572</commentid>
    <comment_count>12</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-12-15 11:18:29 -0800</bug_when>
    <thetext>(In reply to comment #11)
&gt; We can still use FastMalloc from WebKit though, right?

Yes. But as I said earlier &quot;there might be a risk with plug-in compatibility, if plug-ins themselves accidentally mix malloc/free with NPN_MemAlloc and NPN_MemFree.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104114</commentid>
    <comment_count>13</comment_count>
      <attachid>25630</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-01-02 10:53:36 -0800</bug_when>
    <thetext>Comment on attachment 25630
proposed patch

Seems OK to land this as-is. I don&apos;t see a lot of harm in it despite the fact that we&apos;d prefer to use fastMalloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105198</commentid>
    <comment_count>14</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2009-01-11 02:27:17 -0800</bug_when>
    <thetext>Committed revision 39792.

</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>25630</attachid>
            <date>2008-12-01 06:57:20 -0800</date>
            <delta_ts>2009-01-02 10:53:36 -0800</delta_ts>
            <desc>proposed patch</desc>
            <filename>patch.txt</filename>
            <type>text/plain</type>
            <size>3053</size>
            <attacher name="Gabriella Toth">gtoth</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiAzODg2MCkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTcgQEAKKzIwMDgtMTItMDEgIEdhYnJpZWxsYSBUb3RoICA8Z3RvdGhAaW5mLnUt
c3plZ2VkLmh1PgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAg
ICAgIENoZWNraW5nIHdoZXRoZXIgbWFsbG9jIGNhbiBhbGxvY2F0ZSBtZW1vcnkgb3Igbm90LiBJ
ZiBpdCBjYW4ndCwgQ1JBU0ggbWFjcm8gaXMgaW52b2tlZChsaWtlIGluIGZhc3RtYWxsb2MpLgor
ICAgCisgICAgICAgIFdBUk5JTkc6IE5PIFRFU1QgQ0FTRVMgQURERUQgT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ICAgIC8vIFdlIG5ldmVyIHJlbGVhc2UgaWRlbnRpZmllciBu
YW1lcywgc28gdGhpcyBkaWN0aW9uYXJ5IHdpbGwgZ3JvdywgYXMgd2lsbAogICAgICAgICAgICAg
Ly8gdGhlIG1lbW9yeSBmb3IgdGhlIGlkZW50aWZpZXIgbmFtZSBzdHJpbmdzLgogICAgICAgICAg
ICAgaWRlbnRpZmllci0+aXNTdHJpbmcgPSB0cnVlOwpAQCAtMTA0LDYgKzEwNiw4IEBAIE5QSWRl
bnRpZmllciBfTlBOX0dldEludElkZW50aWZpZXIoaW50MzIKICAgICAgICAgaWRlbnRpZmllciA9
IG5lZ2F0aXZlT25lQW5kWmVyb0lkZW50aWZpZXJzW2ludGlkICsgMV07CiAgICAgICAgIGlmICgh
aWRlbnRpZmllcikgewogICAgICAgICAgICAgaWRlbnRpZmllciA9IChQcml2YXRlSWRlbnRpZmll
ciopbWFsbG9jKHNpemVvZihQcml2YXRlSWRlbnRpZmllcikpOworICAgICAgICAgICAgaWYgKCFp
ZGVudGlmaWVyKQorICAgICAgICAgICAgICAgIENSQVNIKCk7CiAgICAgICAgICAgICBpZGVudGlm
aWVyLT5pc1N0cmluZyA9IGZhbHNlOwogICAgICAgICAgICAgaWRlbnRpZmllci0+dmFsdWUubnVt
YmVyID0gaW50aWQ7CiAKQEAgLTExMyw2ICsxMTcsOCBAQCBOUElkZW50aWZpZXIgX05QTl9HZXRJ
bnRJZGVudGlmaWVyKGludDMyCiAgICAgICAgIGlkZW50aWZpZXIgPSBnZXRJbnRJZGVudGlmaWVy
TWFwKCktPmdldChpbnRpZCk7CiAgICAgICAgIGlmICghaWRlbnRpZmllcikgewogICAgICAgICAg
ICAgaWRlbnRpZmllciA9IChQcml2YXRlSWRlbnRpZmllciopbWFsbG9jKHNpemVvZihQcml2YXRl
SWRlbnRpZmllcikpOworICAgICAgICAgICAgaWYgKCFpZGVudGlmaWVyKQorICAgICAgICAgICAg
ICAgIENSQVNIKCk7CiAgICAgICAgICA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3QpKTsKLQorICAgICAgICBpZiAoIW9iaikK
KyAgICAgICAgICAgIENSQVNIKCk7CiAgICAgICAgIG9iai0+X2NsYXNzID0gYUNsYXNzOwogICAg
ICAgICBvYmotPnJlZmVyZW5jZUNvdW50ID0gMTsKIAo=
</data>
<flag name="review"
          id="11943"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>