<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Validating Untrusted Integer Inputs</title>
	<atom:link href="http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html</link>
	<description>Making Your Code Faster, Stronger, Safer…</description>
	<lastBuildDate>Thu, 18 Feb 2010 05:11:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: MYNCTYPE</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-3485</link>
		<dc:creator>MYNCTYPE</dc:creator>
		<pubDate>Mon, 08 Feb 2010 05:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-3485</guid>
		<description>итак: бесподобно...


&lt;a href=&quot;http://myzhchini.co.cc/imki7/?p=11&quot; rel=&quot;nofollow&quot;&gt;хочу замуж&lt;/a&gt; беременная женщина познакомится
&lt;a href=&quot;http://myzhchini.co.cc/tambov1/?p=8&quot; rel=&quot;nofollow&quot;&gt;как познакомиться с молодым человеком в Тамбове&lt;/a&gt;: транс познакомится с парнем
&lt;a href=&quot;http://myzhchini.co.cc/tolyatti2/?p=18&quot; rel=&quot;nofollow&quot;&gt;международное брачное агентство&lt;/a&gt; в Тольяттах ищу парня
&lt;a href=&quot;http://myzhchini.co.cc/podolsk5/?p=8&quot; rel=&quot;nofollow&quot;&gt;девушка познакомится в Подольске с мужчиной&lt;/a&gt;: познакомлюсь в Подольске с мужчиной телефон
&lt;a href=&quot;http://myzhchini.co.cc/kaluga6/?p=10&quot; rel=&quot;nofollow&quot;&gt;Калуга хочу познакомиться с байкером&lt;/a&gt; - познакомлюсь в Калуге с парнем 17 лет
&lt;a href=&quot;http://myzhchini.co.cc/tolyatti2/?p=7&quot; rel=&quot;nofollow&quot;&gt;познакомлюсь с мужчиной с ребенком&lt;/a&gt;: женщина желает познакомиться в Тольяттах для секса
&lt;a href=&quot;http://myzhchini.co.cc/tambov1/?p=9&quot; rel=&quot;nofollow&quot;&gt;хочу найти парня в Тамбове для секса&lt;/a&gt; девушка познакомится в Тамбове с семейной парой
&lt;a href=&quot;http://myzhchini.co.cc/moskva4/?p=30&quot; rel=&quot;nofollow&quot;&gt;хочу виртуального секса с парнем&lt;/a&gt; международное брачное агентство
&lt;a href=&quot;http://myzhchini.co.cc/balakovo7/?p=12&quot; rel=&quot;nofollow&quot;&gt;познакомлюсь в Балаково с мужчиной 60 лет&lt;/a&gt; где познакомиться с врачом в Балаково
&lt;a href=&quot;http://myzhchini.co.cc/kolomna7/?p=10&quot; rel=&quot;nofollow&quot;&gt;секс знакомства с иностранцами&lt;/a&gt;: Коломна хочу мужика
&lt;a href=&quot;http://myzhchini.co.cc/cheboksary6/?p=11&quot; rel=&quot;nofollow&quot;&gt;познакомлюсь с интересным мужчиной&lt;/a&gt; познакомиться с немцем Чебоксары
&lt;a href=&quot;http://myzhchini.co.cc/murom2/?p=7&quot; rel=&quot;nofollow&quot;&gt;познакомлюсь с парнем icq&lt;/a&gt;: познакомиться в Муроме с летчиком
&lt;a href=&quot;http://myzhchini.co.cc/uhta1/?p=8&quot; rel=&quot;nofollow&quot;&gt;девченка хочет секса&lt;/a&gt; - знакомства с австралийцами Ухта
&lt;a href=&quot;http://myzhchini.co.cc/volgodonsk_glazov6/?p=22&quot; rel=&quot;nofollow&quot;&gt;Волгодонск Глазов хочу парня&lt;/a&gt;: в Волгодонске Глазове знакомства с французами
&lt;a href=&quot;http://myzhchini.co.cc/zhukovskij7/?p=8&quot; rel=&quot;nofollow&quot;&gt;познакомлюсь в Жуковском с мужчиной 60 лет&lt;/a&gt;: познакомлюсь для секса с мальчиком
&lt;a href=&quot;http://myzhchini.co.cc/podolsk5/?p=6&quot; rel=&quot;nofollow&quot;&gt;женщина познакомится в Подольске с мужчиной&lt;/a&gt;: познакомиться с французом
&lt;a href=&quot;http://myzhchini.co.cc/podolsk5/?p=11&quot; rel=&quot;nofollow&quot;&gt;хочу познакомиться в Подольске с мальчиком&lt;/a&gt; - хочу познакомиться в Подольске с мальчиком</description>
		<content:encoded><![CDATA[<p>итак: бесподобно&#8230;</p>
<p><a href="http://myzhchini.co.cc/imki7/?p=11" rel="nofollow">хочу замуж</a> беременная женщина познакомится<br />
<a href="http://myzhchini.co.cc/tambov1/?p=8" rel="nofollow">как познакомиться с молодым человеком в Тамбове</a>: транс познакомится с парнем<br />
<a href="http://myzhchini.co.cc/tolyatti2/?p=18" rel="nofollow">международное брачное агентство</a> в Тольяттах ищу парня<br />
<a href="http://myzhchini.co.cc/podolsk5/?p=8" rel="nofollow">девушка познакомится в Подольске с мужчиной</a>: познакомлюсь в Подольске с мужчиной телефон<br />
<a href="http://myzhchini.co.cc/kaluga6/?p=10" rel="nofollow">Калуга хочу познакомиться с байкером</a> &#8211; познакомлюсь в Калуге с парнем 17 лет<br />
<a href="http://myzhchini.co.cc/tolyatti2/?p=7" rel="nofollow">познакомлюсь с мужчиной с ребенком</a>: женщина желает познакомиться в Тольяттах для секса<br />
<a href="http://myzhchini.co.cc/tambov1/?p=9" rel="nofollow">хочу найти парня в Тамбове для секса</a> девушка познакомится в Тамбове с семейной парой<br />
<a href="http://myzhchini.co.cc/moskva4/?p=30" rel="nofollow">хочу виртуального секса с парнем</a> международное брачное агентство<br />
<a href="http://myzhchini.co.cc/balakovo7/?p=12" rel="nofollow">познакомлюсь в Балаково с мужчиной 60 лет</a> где познакомиться с врачом в Балаково<br />
<a href="http://myzhchini.co.cc/kolomna7/?p=10" rel="nofollow">секс знакомства с иностранцами</a>: Коломна хочу мужика<br />
<a href="http://myzhchini.co.cc/cheboksary6/?p=11" rel="nofollow">познакомлюсь с интересным мужчиной</a> познакомиться с немцем Чебоксары<br />
<a href="http://myzhchini.co.cc/murom2/?p=7" rel="nofollow">познакомлюсь с парнем icq</a>: познакомиться в Муроме с летчиком<br />
<a href="http://myzhchini.co.cc/uhta1/?p=8" rel="nofollow">девченка хочет секса</a> &#8211; знакомства с австралийцами Ухта<br />
<a href="http://myzhchini.co.cc/volgodonsk_glazov6/?p=22" rel="nofollow">Волгодонск Глазов хочу парня</a>: в Волгодонске Глазове знакомства с французами<br />
<a href="http://myzhchini.co.cc/zhukovskij7/?p=8" rel="nofollow">познакомлюсь в Жуковском с мужчиной 60 лет</a>: познакомлюсь для секса с мальчиком<br />
<a href="http://myzhchini.co.cc/podolsk5/?p=6" rel="nofollow">женщина познакомится в Подольске с мужчиной</a>: познакомиться с французом<br />
<a href="http://myzhchini.co.cc/podolsk5/?p=11" rel="nofollow">хочу познакомиться в Подольске с мальчиком</a> &#8211; хочу познакомиться в Подольске с мальчиком</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zombie No. 5</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-693</link>
		<dc:creator>Zombie No. 5</dc:creator>
		<pubDate>Mon, 06 Apr 2009 20:06:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-693</guid>
		<description>This is so bad, it has to be a joke.

What is null? It isn&#039;t defined anywhere.
The parameter given to malloc() is most certainly not what you meant. That is also an opportinity for an overflow in general. You would have to check that size is smaller than SIZE_MAX divided by the element size. Otherwise, the multiplication my wrap and you request less from malloc than intented and cause a heap overflow when writing beyond the resulting array.

SIZE_MAX is the maximum value for size_t and unsigned integer type. There&#039;s likely no platform where INT_MAX is larger or equal to SIZE_MAX. Hence you don&#039;t prevent an integer overflow at all. There&#039;s no point to check size at that place anyway. What you have to check there is the returned pointer by malloc.

Likewise your documentation and code should make clear whether the size and MAX_SIZE_OF_STRING include the terminating NUL or not. Big difference and another typical cause of a buffer overrun.

There&#039;s little to no point in checking a pointer against NULL - whatever null may be - before passing it to free(). free() handles NULL just fine by definition.

There&#039;s also no reason at all to cast the result of malloc(). Casts should be avoided whenever possible because they suppress useful compiler warnings.</description>
		<content:encoded><![CDATA[<p>This is so bad, it has to be a joke.</p>
<p>What is null? It isn&#8217;t defined anywhere.<br />
The parameter given to malloc() is most certainly not what you meant. That is also an opportinity for an overflow in general. You would have to check that size is smaller than SIZE_MAX divided by the element size. Otherwise, the multiplication my wrap and you request less from malloc than intented and cause a heap overflow when writing beyond the resulting array.</p>
<p>SIZE_MAX is the maximum value for size_t and unsigned integer type. There&#8217;s likely no platform where INT_MAX is larger or equal to SIZE_MAX. Hence you don&#8217;t prevent an integer overflow at all. There&#8217;s no point to check size at that place anyway. What you have to check there is the returned pointer by malloc.</p>
<p>Likewise your documentation and code should make clear whether the size and MAX_SIZE_OF_STRING include the terminating NUL or not. Big difference and another typical cause of a buffer overrun.</p>
<p>There&#8217;s little to no point in checking a pointer against NULL &#8211; whatever null may be &#8211; before passing it to free(). free() handles NULL just fine by definition.</p>
<p>There&#8217;s also no reason at all to cast the result of malloc(). Casts should be avoided whenever possible because they suppress useful compiler warnings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gustavo Serra</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-160</link>
		<dc:creator>Gustavo Serra</dc:creator>
		<pubDate>Mon, 16 Feb 2009 13:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-160</guid>
		<description>str = (char*)malloc( size * sizeof(char*));

Are you really trying to allocate an array of pointers to char?</description>
		<content:encoded><![CDATA[<p>str = (char*)malloc( size * sizeof(char*));</p>
<p>Are you really trying to allocate an array of pointers to char?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amit Goel</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-69</link>
		<dc:creator>Amit Goel</dc:creator>
		<pubDate>Mon, 19 Jan 2009 18:48:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-69</guid>
		<description>@Lee, Mihail, stu,

Thanks for correcting the code. But In this post, I wanted to emphasize on the usage of integer inputs (for example: &#039;size&#039; variable). 

I do understand your concerns of not validating the return values or codes of the function calls but then, that was not the main agenda in this code segment. and Ofcourse, I did not expect a stringent code review :-)</description>
		<content:encoded><![CDATA[<p>@Lee, Mihail, stu,</p>
<p>Thanks for correcting the code. But In this post, I wanted to emphasize on the usage of integer inputs (for example: &#8217;size&#8217; variable). </p>
<p>I do understand your concerns of not validating the return values or codes of the function calls but then, that was not the main agenda in this code segment. and Ofcourse, I did not expect a stringent code review <img src='http://www.safercode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stu</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-64</link>
		<dc:creator>stu</dc:creator>
		<pubDate>Fri, 16 Jan 2009 20:01:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-64</guid>
		<description>Why not just limit what size can be by anding:

size =&amp; 0x07ff;

Size can not exceed that value. If it is bigger when passed in it will be reduced, and if signed will be converted in to an unsigned int. Trying to use a signed it to malloc memory is a not recommended. How many people need -1 bytes :)

Also as others have said initialise all local variables to a know value, check all returns (even printf) and take no short cuts.</description>
		<content:encoded><![CDATA[<p>Why not just limit what size can be by anding:</p>
<p>size =&amp; 0&#215;07ff;</p>
<p>Size can not exceed that value. If it is bigger when passed in it will be reduced, and if signed will be converted in to an unsigned int. Trying to use a signed it to malloc memory is a not recommended. How many people need -1 bytes <img src='http://www.safercode.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also as others have said initialise all local variables to a know value, check all returns (even printf) and take no short cuts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mihail</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-63</link>
		<dc:creator>Mihail</dc:creator>
		<pubDate>Fri, 16 Jan 2009 18:11:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-63</guid>
		<description>By testing for str to be equal to null, you introduce code that might run sometimes, and not some other times.
The ANSI C standard doesn&#039;t say anything about local variables being initialized to a certain value (you&#039;re assuming the compiler sets it to null, but it not necessary true).
Also, you fail to test if the malloc() was succesful (though in case it is not, there isn&#039;t much you can do but exit).

Regards,
Mihail.</description>
		<content:encoded><![CDATA[<p>By testing for str to be equal to null, you introduce code that might run sometimes, and not some other times.<br />
The ANSI C standard doesn&#8217;t say anything about local variables being initialized to a certain value (you&#8217;re assuming the compiler sets it to null, but it not necessary true).<br />
Also, you fail to test if the malloc() was succesful (though in case it is not, there isn&#8217;t much you can do but exit).</p>
<p>Regards,<br />
Mihail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lee</title>
		<link>http://www.safercode.com/blog/2008/10/21/validating-untrusted-integer-inputs.html#comment-62</link>
		<dc:creator>Lee</dc:creator>
		<pubDate>Fri, 16 Jan 2009 18:02:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.safercode.com/blog/?p=5#comment-62</guid>
		<description>There is an error in the 2nd example.  An assumption is made that the newly declared pointer str is null before it is malloc&#039;d.  Since the pointer is not initialized, that may not reliably be so (depending on the compiler used I suppose).

It would be better to add an initialization to the declaration :

 char *str = (char *)null;

Otherwise the way it is coded, it is possible that the free call will cause a seg fault.</description>
		<content:encoded><![CDATA[<p>There is an error in the 2nd example.  An assumption is made that the newly declared pointer str is null before it is malloc&#8217;d.  Since the pointer is not initialized, that may not reliably be so (depending on the compiler used I suppose).</p>
<p>It would be better to add an initialization to the declaration :</p>
<p> char *str = (char *)null;</p>
<p>Otherwise the way it is coded, it is possible that the free call will cause a seg fault.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
