<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Matasano Chargen - Latest Comments in TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://matasanochargen.disqus.com/</link><description></description><language>en</language><lastBuildDate>Tue, 24 Jul 2007 00:58:30 -0000</lastBuildDate><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321358</link><description>The whole point of using shared_ptr is not making any naked pointers at all. What kind of C++ libraries are you talking about, that require pointers and are critical to the project survival?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lenik</dc:creator><pubDate>Tue, 24 Jul 2007 00:58:30 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321357</link><description>Types (1) and (2) are the same thing. The contents of objects are not part of their API; that's the point of encapsulation. So there are only 2 types of objects in considerations:&lt;br&gt;&lt;br&gt;1. Block scoped objects&lt;br&gt;&lt;br&gt;2. Not block scoped objects&lt;br&gt;&lt;br&gt;The "not block scoped" case is the majority of all objects in nontrivial code.&lt;br&gt;&lt;br&gt;You've now introduced shared_ptr as a means of eradicating delete calls for that case. But shared_ptr has its own dangers. C++ libraries, including some of the standard libraries, aren't &lt;br&gt;designed to retain shared_ptrs with type intact. The moment you alias a shared_ptr to a naked pointer, you've introduced another, scarier class of bugs.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thomas Ptacek</dc:creator><pubDate>Thu, 19 Jul 2007 11:09:29 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321356</link><description>well, let's pitch again RAII and delete =)&lt;br&gt;&lt;br&gt;there are, generally speaking, three types of objects:&lt;br&gt;&lt;br&gt;1. small objects which are block scoped&lt;br&gt;2. not-so-small objects which are block scoped&lt;br&gt;3. other long-living objects&lt;br&gt;&lt;br&gt;Objects of the first kind could be easily created on stack without new/delete hassle and even without any RAII -- they will be automatically destroyed when the block ends.&lt;br&gt;&lt;br&gt;Objects of the second kind usually cannot be allocated on stack because of their size, so we need  some kind of RAII wrapper, which frees the memory when object goes out of scope.&lt;br&gt;&lt;br&gt;Third kind of objects is the most interesting, but still very simple to deal with. Object definition/declaration should be wrapped in auto_ptr (or shared_ptr or any ptr wrapper of your choice), and delete is either simply removed or replaced with trivial sink() construct if you prefer to release memory immediately and don't want to wait until the program termination.&lt;br&gt;&lt;br&gt;Actually, I sometimes do a lot of bugfixing in someone else's code. And beforementioned steps are the first I do to deal with incorrect exception handling and/or memory leaks. Works like charm =)</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lenik</dc:creator><pubDate>Thu, 19 Jul 2007 02:21:42 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321355</link><description>I buy that you can evict delete[] with vectors.&lt;br&gt;&lt;br&gt;I don't buy that you can evict delete with RAII. &lt;br&gt;&lt;br&gt;In any nontrivial project, a sizeable portion of all your objects won't be block-scoped.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thomas Ptacek</dc:creator><pubDate>Wed, 18 Jul 2007 11:22:33 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321354</link><description>maybe i should have replied on &lt;a href="http://www.matasano.com/log/914/c-a-cautionary-tale-or-1-hour-of-your-black-hat-trip-is-spoken-for/" rel="nofollow"&gt;this page&lt;/a&gt;, which discusses same issues, but it looks already a bit too crowded...</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lenik</dc:creator><pubDate>Wed, 18 Jul 2007 01:57:21 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321353</link><description>Thanks, I did not really expected anyone to read this but you =)&lt;br&gt;&lt;br&gt;What I actually wanted to say is, you are right, "delete/[]" are harmful. And the rule is very simple -- don't use "delete/[]". Every time when starting to assess another project, start with grep'ing on "delete" and then "blame" in your favourite version control system. A good project should have no "delete" constructs anywhere, except maybe one or two well tested and documented places.&lt;br&gt;&lt;br&gt;And if the project does not have any "delete" left, there shouldn't be any problem with them anymore?&lt;br&gt;&lt;br&gt;After we have answered the first part of the question, "what to do?", there's a second part which sounds "how?", and "vectors and RAII" is the answer.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lenik</dc:creator><pubDate>Wed, 18 Jul 2007 01:35:41 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321352</link><description>Also: what on earth does RAII have to do with delete[]? Maybe you meant to say, "there are dozens of books on how to use vector instead of arrays".</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thomas Ptacek</dc:creator><pubDate>Tue, 17 Jul 2007 10:36:47 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321351</link><description>First, you're responding to a post that's 7 months old, so nobody is going to read your comment.&lt;br&gt;&lt;br&gt;Second, you've misunderstood the whole point of the post. It's not that anyone's "discovered" delete/delete[]. You're right, it's a textbook example of a C++ coding mistake, and one everyone learns when they blunder into it in their first year of writing C++.&lt;br&gt;&lt;br&gt;The point is, like a growing portion of C/C++ coding flaws, we are discovering ways to weaponize the flaw, turning it from a simple bug to an exploitable security flaw.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thomas Ptacek</dc:creator><pubDate>Tue, 17 Jul 2007 10:35:45 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321350</link><description>Writing about delete/delete[] in 2007 is just plain pathetic, because there are dozens of C++ books out there explaining how to use RAII and similiar approaches. And if someone has not read them yet, he just needs a good pointer to the bookshelf.&lt;br&gt;&lt;br&gt;And about "arrays of THOSE objects" -- it's very easy, especially using STL vectors. Need an array? Here it is: vector array; Need an array of arrays? Nothing is easier: vector &amp;gt; array_of_arrays.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">lenik</dc:creator><pubDate>Tue, 17 Jul 2007 04:32:25 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321349</link><description>RAII only works in situations where the lifetime of an object can be tied directly to its scope. You have a stronger argument for "wrap arrays in objects that can issue delete[] in the dtor", but then you can't create arrays of THOSE objects.&lt;br&gt;&lt;br&gt;And yes, you'd be insane to consider C++ for a new project in 2007.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Thomas Ptacek</dc:creator><pubDate>Wed, 10 Jan 2007 16:36:41 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321347</link><description>While C++ allows you to code in such a way that you make this mistake, it's powerful enough to support a much safer coding paradigm:&lt;br&gt;&lt;br&gt;AutoPtr foo = Create();&lt;br&gt;AutoArray fooArray = CreateArray(12);&lt;br&gt;&lt;br&gt;When you're done with the pointers, these objects will release your allocations in the appropriate manner.&lt;br&gt;&lt;br&gt;Using C++ without RAII resource management has always struck me as only driving your Porsche in first gear.  You can get places, but it's a crying shame to see.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">ploer</dc:creator><pubDate>Wed, 10 Jan 2007 15:48:00 -0000</pubDate></item><item><title>Re: TAOSSA on Novel C++ Bug Class: delete/delete[]</title><link>http://www.matasano.com/log/663/taossa-on-novel-c-bug-class-deletedelete/#comment-2321348</link><description>Would I be insane for considering C++ in a new project where Java would suffice for 95% of it (part of it has to be in C)?&lt;br&gt;&lt;br&gt;A few weeks ago it would have been C or C++ without a question.  But with the prospect of hiring some new developers, I have to think about their knowledge as well.  I can write safe C and C++ code, but can they?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Slacker</dc:creator><pubDate>Wed, 03 Jan 2007 14:09:33 -0000</pubDate></item></channel></rss>