<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx</link><description>I was reading this months issue of Dr. Dobbs Journal, and I ran into the column " Illusions of Safety " by Pete Becker. Pete writes about enhancements to the C language, and I usually really enjoy his columns. This month was an exception. Pete basically</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#1135181</link><pubDate>Fri, 24 Nov 2006 06:03:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1135181</guid><dc:creator>Jdev</dc:creator><description>&lt;p&gt;If C# and C++ are too slow, then switch to Java.&lt;/p&gt;
&lt;p&gt;I switched and never looked back.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1135181" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#948227</link><pubDate>Sat, 04 Nov 2006 02:13:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:948227</guid><dc:creator>Chris Lightfoot</dc:creator><description>&lt;p&gt;He's not claiming that you should use assert(3) for parameter validation; indeed in that bit of the article he explicitly states that he wants to avoid doing parameter validation everywhere on efficiency grounds(!). The assert is just an expression of the &amp;quot;contract&amp;quot; of the function. Sure, the suggestions are pretty silly, but not really in the way you suggest, at least in that case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=948227" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#892331</link><pubDate>Sun, 29 Oct 2006 05:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:892331</guid><dc:creator>c</dc:creator><description>&lt;p&gt;&amp;quot;A few days ago I used _tcscpy safely. &amp;nbsp;I ran a few _tsclen calls, added the results, did a malloc, checked the result of malloc, and then if still running I copied each string to the appropriate portion of the resulting buffer.&amp;quot;&lt;/p&gt;
&lt;p&gt;Did you remember to check to for overflow on your addition?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=892331" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#871176</link><pubDate>Wed, 25 Oct 2006 08:37:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:871176</guid><dc:creator>DaveZero</dc:creator><description>&lt;p&gt;As I understand it, the main argument against to &amp;quot;Why stop here [C++] and not switch to C# or VB[.NET]?&amp;quot; is that C++ is still a LOT faster running...like 16 to 64 times faster...mostly due to the asbsence of strict variable typing and the direct access it affords to memory. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;That's how I used to think even just a few years ago, and I still do, to the extent that I think unmanaged code is still a hellalot better for, say, massive scientific simulations and the like, because it's still WAY WAY WAY faster, deny it all you like.&lt;/p&gt;
&lt;p&gt;However, for pretty much any business-related project I could imagine, and most anything else non-scientific (or gaming), the hardware is now simply so fast that: who cares how much slower managed code executes?...it's just not generally an issue that it runs many times slower. &amp;nbsp;So, in the final analysis, I would never use C or even C++ for anything usual, especially if I needed the result to securly withstand public use.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=871176" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#817138</link><pubDate>Wed, 11 Oct 2006 19:42:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:817138</guid><dc:creator>kiwiblue</dc:creator><description>&lt;p&gt;&amp;gt; The real solution is to use C++&lt;/p&gt;
&lt;p&gt;Why stop here and not switch to C# or VB?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=817138" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#815581</link><pubDate>Wed, 11 Oct 2006 04:14:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:815581</guid><dc:creator>sohail</dc:creator><description>&lt;p&gt;The real solution is to use C++&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=815581" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#803067</link><pubDate>Sun, 08 Oct 2006 04:55:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:803067</guid><dc:creator>ndiamond</dc:creator><description>&lt;p&gt;Friday, October 06, 2006 3:03 AM by Phaeron&lt;/p&gt;
&lt;p&gt;&amp;gt; formal proof of buffer overflow impossibility through static&lt;/p&gt;
&lt;p&gt;&amp;gt; analysis and design is a MUCH better way to produce secure&lt;/p&gt;
&lt;p&gt;&amp;gt; software than runtime buffer size checks?&lt;/p&gt;
&lt;p&gt;That is 100% true.&lt;/p&gt;
&lt;p&gt;For some kinds of programs you can do a formal proof. &amp;nbsp;How do you construct a formal proof? &amp;nbsp;In my experience it was done by humans applying logic to demonstrate that each fact is provable from previously proven facts. &amp;nbsp;In other words, humans were applying the same logic that humans apply in writing programs. &amp;nbsp;So the bug rate wasn't zero, the bug rate might potentially be geometrically lower (two simultaneous failures being geometrically less probable than one failure), but the actual results weren't that good.&lt;/p&gt;
&lt;p&gt;In the general case there won't always be even a theoretical possibility of a formal proof. &amp;nbsp;It reduces to the halting problem.&lt;/p&gt;
&lt;p&gt;Now, C strings are miserable. &amp;nbsp;Most of the C language combines the power of assembly language with the beauty of assembly language because it was invented as a substitute for assembly language. &amp;nbsp;Of course since being standardized it's not always possible to use it that way any more, but it still reflects the beauty of its origins (^_irony). &amp;nbsp;The strings section of the library seems to have been designed more hastily. &amp;nbsp;It took advantage of machine instructions which an assembly language programmer could code quickly for one kind of machine. &amp;nbsp;It didn't prepare for efficient but harder coding that would measure once before copying and concatenating and comparing several times. &amp;nbsp;C++, being object-oriented assembly assembly, derives with the same weak base, though it's a bit easier to make counted string libraries that will be easily usable by clients.&lt;/p&gt;
&lt;p&gt;A few days ago I used _tcscpy safely. &amp;nbsp;I ran a few _tsclen calls, added the results, did a malloc, checked the result of malloc, and then if still running I copied each string to the appropriate portion of the resulting buffer. &amp;nbsp;Then I cringed at the thought of what will happen when someone copies and pastes the code without figuring out why it was OK this once. &amp;nbsp;I wished I could just use VB's &amp;amp; operator instead.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=803067" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#795588</link><pubDate>Fri, 06 Oct 2006 10:03:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:795588</guid><dc:creator>Phaeron</dc:creator><description>I think the real point of the article is being missed here. Surely everyone here would agree that formal proof of buffer overflow impossibility through static analysis and design is a MUCH better way to produce secure software than runtime buffer size checks? Just checking string bounds isn't always enough -- you have to make sure that a truncated string isn't used in a way that could cause a different vulnerability, or that throwing exceptions doesn't allow an easy way to cause a DoS, etc. I don't think bounds checking is a bad idea, as it definitely helps with robustness as well as security (think hardware errors!), but it's not a _great_ solution. For calls that are solely internal, it's a bit like speculatively adding try/catch.

Personally, I would rather see more emphasis on language features and tools that help me declare and enforce guarantees at compile time, because that would help avoid a lot more problems than just buffer overflows.

Also, I think the performance issue is a bit of a red herring, not because the checks are "free" -- they aren't, either in runtime or code size cost -- but because string operations themselves aren't cheap, and overuse of strings is a common performance problem.
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=795588" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#794543</link><pubDate>Thu, 05 Oct 2006 23:15:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:794543</guid><dc:creator>Anony Moose</dc:creator><description>If you're the world's best and safest driver, seatbelts protect you from all the morons out there.

If you're the world's best and safest programmer, safe string copy functions protect your code from all the morons out there who accidentally work around your safety checks.

And, also, if you're not quite as great as you think you are, they keep you from getting a whole lot of egg on your face.  ;)
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=794543" width="1" height="1"&gt;</description></item><item><title>re: Sometimes people don't really get the point of defensive programming for security...</title><link>http://blogs.msdn.com/b/larryosterman/archive/2006/10/04/sometimes-people-don_2700_t-really-get-the-point-of-defensive-programming-for-security_2E00__2E00__2E00_.aspx#794150</link><pubDate>Thu, 05 Oct 2006 19:33:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:794150</guid><dc:creator>Larry Osterman [MSFT]</dc:creator><description>&lt;p&gt;sergei: Interesting. &amp;nbsp;I've never heard of that usage for strncpy (checking the byte at &amp;lt;length&amp;gt; for 0). &amp;nbsp;I much prefer APIs that return errors when they fail as opposed to having to probe for side-effects.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=794150" width="1" height="1"&gt;</description></item></channel></rss>