<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/1.5.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: GCC vs. CERT</title>
	<link>http://www.airs.com/blog/archives/174</link>
	<description>Ian Lance Taylor</description>
	<pubDate>Tue, 18 Nov 2008 21:43:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.2</generator>

	<item>
 		<title>Comment on GCC vs. CERT by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/174#comment-12658</link>
		<pubDate>Thu, 24 Apr 2008 00:10:49 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12658</guid>
					<description>Thanks very much for the pointer.</description>
		<content:encoded><![CDATA[	<p>Thanks very much for the pointer.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: dbremner</title>
		<link>http://www.airs.com/blog/archives/174#comment-12641</link>
		<pubDate>Wed, 23 Apr 2008 19:48:21 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12641</guid>
					<description>Russ Cox reported this as a vulnerability to CERT. The original broken code is &lt;a href=&quot;http://groups.google.com/group/comp.os.plan9/msg/d5c0a5836622f0c9&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.   
I'm disappointed by CERT's response.</description>
		<content:encoded><![CDATA[	<p>Russ Cox reported this as a vulnerability to CERT. The original broken code is <a href="http://groups.google.com/group/comp.os.plan9/msg/d5c0a5836622f0c9" rel="nofollow">here</a>.<br />
I&#8217;m disappointed by CERT&#8217;s response.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/174#comment-12323</link>
		<pubDate>Sat, 12 Apr 2008 01:07:09 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12323</guid>
					<description>Knieper: thanks for the example.  It's almost plausible.  Of course it's better to rewrite the incorrect test as

if (len &amp;#62; max - ptr)
  return EINVAL;

rather than to rely on wrapping overflow.  (Let's not forget that the C language standard specifically says that pointer overflow is undefined, and that it will not work as you expect on a segmented memory architecture).

You're right, gcc PR 27180 was an earlier iteration of this.  it was made to work correctly--that is, to optimize those comparisons only when appropriate--with gcc PR 27039.</description>
		<content:encoded><![CDATA[	<p>Knieper: thanks for the example.  It&#8217;s almost plausible.  Of course it&#8217;s better to rewrite the incorrect test as</p>
	<p>if (len &gt; max - ptr)<br />
  return EINVAL;</p>
	<p>rather than to rely on wrapping overflow.  (Let&#8217;s not forget that the C language standard specifically says that pointer overflow is undefined, and that it will not work as you expect on a segmented memory architecture).</p>
	<p>You&#8217;re right, gcc PR 27180 was an earlier iteration of this.  it was made to work correctly&#8211;that is, to optimize those comparisons only when appropriate&#8211;with gcc PR 27039.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/174#comment-12322</link>
		<pubDate>Sat, 12 Apr 2008 00:54:24 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12322</guid>
					<description>ncm: strlcpy lets you write sloppy code faster without introducing buffer overflow.  I guess I do have to agree that any fully correct use of strlcpy can be replaced by memcpy.  String truncation at a relatively arbitrary point is only rarely the right thing to do.</description>
		<content:encoded><![CDATA[	<p>ncm: strlcpy lets you write sloppy code faster without introducing buffer overflow.  I guess I do have to agree that any fully correct use of strlcpy can be replaced by memcpy.  String truncation at a relatively arbitrary point is only rarely the right thing to do.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Knieper</title>
		<link>http://www.airs.com/blog/archives/174#comment-12321</link>
		<pubDate>Fri, 11 Apr 2008 20:16:24 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12321</guid>
					<description>&amp;#62;The advisory is about an optimization which gcc
&amp;#62;introduced in gcc 4.2
No, it's an old bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27180

&amp;#62;This means in particular that p + C can not wrap
&amp;#62;around the end of memory, so the compiler can
&amp;#62;ignore wrapping issues.
&amp;#62;Now, I don’t know who would have thought otherwise.

&amp;#62;What matters is whether the offset is within the
&amp;#62;bounds of the object the pointer points at. A test
&amp;#62;which relies on wrapping overflow for pointer bounds
&amp;#62;seems rather strange.

http://www.fefe.de/openldap-mail.txt</description>
		<content:encoded><![CDATA[	<p>&gt;The advisory is about an optimization which gcc<br />
&gt;introduced in gcc 4.2<br />
No, it&#8217;s an old bug: <a href='http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27180' rel='nofollow'>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27180</a></p>
	<p>&gt;This means in particular that p + C can not wrap<br />
&gt;around the end of memory, so the compiler can<br />
&gt;ignore wrapping issues.<br />
&gt;Now, I don’t know who would have thought otherwise.</p>
	<p>&gt;What matters is whether the offset is within the<br />
&gt;bounds of the object the pointer points at. A test<br />
&gt;which relies on wrapping overflow for pointer bounds<br />
&gt;seems rather strange.</p>
	<p><a href='http://www.fefe.de/openldap-mail.txt' rel='nofollow'>http://www.fefe.de/openldap-mail.txt</a>
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: ncm</title>
		<link>http://www.airs.com/blog/archives/174#comment-12320</link>
		<pubDate>Fri, 11 Apr 2008 18:42:30 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12320</guid>
					<description>strlcpy, in isolation, wouldn't be so bad.  What makes it actionably bad is &quot;security professionals&quot; insisting that every strcpy call be replaced by strlcpy.  

That said, it's a bad design because it doesn't pull its weight: it's just as much work (and code) to check the result as it would have been to pass verified-safe arguments to memcpy.  Furthermore, there's nothing meaningful to do if it comes out wrong.  It's not so bad as strtok, which represents the extremum of standardized interface design stupidity. (I don't doubt MS has surpassed it privately, but who could find out without home trepanation?)</description>
		<content:encoded><![CDATA[	<p>strlcpy, in isolation, wouldn&#8217;t be so bad.  What makes it actionably bad is &#8220;security professionals&#8221; insisting that every strcpy call be replaced by strlcpy.  </p>
	<p>That said, it&#8217;s a bad design because it doesn&#8217;t pull its weight: it&#8217;s just as much work (and code) to check the result as it would have been to pass verified-safe arguments to memcpy.  Furthermore, there&#8217;s nothing meaningful to do if it comes out wrong.  It&#8217;s not so bad as strtok, which represents the extremum of standardized interface design stupidity. (I don&#8217;t doubt MS has surpassed it privately, but who could find out without home trepanation?)
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Christoph Bartoschek</title>
		<link>http://www.airs.com/blog/archives/174#comment-12318</link>
		<pubDate>Fri, 11 Apr 2008 11:42:44 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12318</guid>
					<description>Somehow my program example got mangled through the posting process. Did not notice it earlier.

Unfortunately you are right. Deciding about which removed code should be warned is very hard.</description>
		<content:encoded><![CDATA[	<p>Somehow my program example got mangled through the posting process. Did not notice it earlier.</p>
	<p>Unfortunately you are right. Deciding about which removed code should be warned is very hard.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Danilo Piazzalunga</title>
		<link>http://www.airs.com/blog/archives/174#comment-12317</link>
		<pubDate>Fri, 11 Apr 2008 08:16:26 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12317</guid>
					<description>ncm: I never understood why strlcpy() is considered that bad. I agree with Ian in finding strlcpy() just a nicer strncpy().</description>
		<content:encoded><![CDATA[	<p>ncm: I never understood why strlcpy() is considered that bad. I agree with Ian in finding strlcpy() just a nicer strncpy().
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/174#comment-12315</link>
		<pubDate>Thu, 10 Apr 2008 20:04:21 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12315</guid>
					<description>I haven't actually tried your program, but it is yet another case.  In standard C there is nothing you can add to a non-null pointer which will give you a null pointer.

It doesn't make sense to me to have a warning for every code block that is optimized out.  It will happen too often--there will be too many false positives.  Think about inline functions, for example, when called with constant arguments.

I also don't think a warning for the type of code in your example is useful.  What real code would it help?

There is an easy way to ensure that nothing gets optimized out: compile with -O0.</description>
		<content:encoded><![CDATA[	<p>I haven&#8217;t actually tried your program, but it is yet another case.  In standard C there is nothing you can add to a non-null pointer which will give you a null pointer.</p>
	<p>It doesn&#8217;t make sense to me to have a warning for every code block that is optimized out.  It will happen too often&#8211;there will be too many false positives.  Think about inline functions, for example, when called with constant arguments.</p>
	<p>I also don&#8217;t think a warning for the type of code in your example is useful.  What real code would it help?</p>
	<p>There is an easy way to ensure that nothing gets optimized out: compile with -O0.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on GCC vs. CERT by: Christoph Bartoschek</title>
		<link>http://www.airs.com/blog/archives/174#comment-12310</link>
		<pubDate>Thu, 10 Apr 2008 10:29:20 +0000</pubDate>
		<guid>http://www.airs.com/blog/archives/174#comment-12310</guid>
					<description>I wonder why the following programm does not give a warning for the first if statement similar to the warning for the second statement:

#include 
#include 

int main(void) {
        char buf[1];
        unsigned pos = 1;
        int  len = INT_MAX;

        if (buf+len= 0) printf(&quot;Bigger\n&quot;);
        return 0;
}

I used version 4.3 and:
gcc -O2 -W -Wall -pedantic -Wstrict-overflow=5 fehler.c

Generally  I would like to have a warning for each code block that is optimized out and a possibility to disable the warning for specific code blocks.</description>
		<content:encoded><![CDATA[	<p>I wonder why the following programm does not give a warning for the first if statement similar to the warning for the second statement:</p>
	<p>#include<br />
#include </p>
	<p>int main(void) {<br />
        char buf[1];<br />
        unsigned pos = 1;<br />
        int  len = INT_MAX;</p>
	<p>        if (buf+len= 0) printf(&#8221;Bigger\n&#8221;);<br />
        return 0;<br />
}</p>
	<p>I used version 4.3 and:<br />
gcc -O2 -W -Wall -pedantic -Wstrict-overflow=5 fehler.c</p>
	<p>Generally  I would like to have a warning for each code block that is optimized out and a possibility to disable the warning for specific code blocks.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
