<?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: How to Write a Secure Code in C/C++ Programming Languages</title>
	<atom:link href="http://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/</link>
	<description>All about electronics and circuit design</description>
	<lastBuildDate>Wed, 22 Apr 2026 18:32:18 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.14</generator>
	<item>
		<title>By: Tomi Engdahl</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1551482</link>
		<dc:creator><![CDATA[Tomi Engdahl]]></dc:creator>
		<pubDate>Sat, 17 Jun 2017 07:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1551482</guid>
		<description><![CDATA[3 security tips for software developers
Don&#039;t make these common security mistakes that leave you vulnerable to attack.
https://opensource.com/article/17/6/3-security-musts-software-developers?sc_cid=7016000000127ECAAY

Every developer knows the importance of following best security practices. But too often we cut corners, maybe because we have to work hard until those security practices sink in. Unfortunately, that usually takes something like seeing a security malpractice that&#039;s so bad it gets marked in indelible ink in our brains.]]></description>
		<content:encoded><![CDATA[<p>3 security tips for software developers<br />
Don&#8217;t make these common security mistakes that leave you vulnerable to attack.<br />
<a href="https://opensource.com/article/17/6/3-security-musts-software-developers?sc_cid=7016000000127ECAAY" rel="nofollow">https://opensource.com/article/17/6/3-security-musts-software-developers?sc_cid=7016000000127ECAAY</a></p>
<p>Every developer knows the importance of following best security practices. But too often we cut corners, maybe because we have to work hard until those security practices sink in. Unfortunately, that usually takes something like seeing a security malpractice that&#8217;s so bad it gets marked in indelible ink in our brains.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: maryjane</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1550783</link>
		<dc:creator><![CDATA[maryjane]]></dc:creator>
		<pubDate>Tue, 13 Jun 2017 07:47:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1550783</guid>
		<description><![CDATA[nice information.]]></description>
		<content:encoded><![CDATA[<p>nice information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: may chay bo cao cap</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1549557</link>
		<dc:creator><![CDATA[may chay bo cao cap]]></dc:creator>
		<pubDate>Sun, 04 Jun 2017 04:30:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1549557</guid>
		<description><![CDATA[Definitely believe that which you stated. Your favorite reason appeared to be on the web 
the easiest thing to be aware of. I say to you, I certainly get annoyed while 
people think about worries that they plainly don&#039;t know about.
You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal.
Will likely be back to get more. Thanks]]></description>
		<content:encoded><![CDATA[<p>Definitely believe that which you stated. Your favorite reason appeared to be on the web<br />
the easiest thing to be aware of. I say to you, I certainly get annoyed while<br />
people think about worries that they plainly don&#8217;t know about.<br />
You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal.<br />
Will likely be back to get more. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomi Engdahl</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1549386</link>
		<dc:creator><![CDATA[Tomi Engdahl]]></dc:creator>
		<pubDate>Fri, 02 Jun 2017 11:26:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1549386</guid>
		<description><![CDATA[When we are talking about &quot;safer&quot; &quot;n&quot; versions, remember also this case with strncmp() on Intel AMP bug
https://arstechnica.com/security/2017/05/the-hijacking-flaw-that-lurked-in-intel-chips-is-worse-than-anyone-thought

The bug was in the code to compare the two strings. It used the strncmp function that compares the first N characters of two strings:

strncmp(string1, string2, N)

This would work just fine for hashes sent by the browser, which are always 32 characters in length. Even if the password field is empty, it would compare the two strings, they wouldn&#039;t match, and it would reject the empty password or invalid password.

The problem is what happens if you don&#039;t use a browser, but you generate an invalid request manually or using a proxy to alter the response, sending an empty string instead of the 32 character hash. Then the compare code does this:

strncmp(&quot;6629fae49393a05397450978507c4ef1&quot;,&quot;&quot;,0)

This means the function will compare the first 0 characters between the two strings. So it is equivalent to:

strncmp(&quot;&quot;,&quot;&quot;,0)

Of course, two 0 length strings are equal, so it wrongfully concludes the hashes are equal.

What the programmer should have done is check if the hash coming from the browser has the correct length, 32 characters, before attempting to compare the two strings.

Or even better, the programmer should have used the proper string comparing function, strcmp, that already does that for you and you don&#039;t need to supply a length parameter

The very fact that we&#039;re debating if it was the handwork of a 3 letter agency or pure incompetence is a worrying sign of the times were in.

But to think that this flaw went on for 7 years... Were they just copying and pasting the AMT code from generation to generation? We&#039;re talking about Intel here, the guys who seem to release a new processor with every full moon.]]></description>
		<content:encoded><![CDATA[<p>When we are talking about &#8220;safer&#8221; &#8220;n&#8221; versions, remember also this case with strncmp() on Intel AMP bug<br />
<a href="https://arstechnica.com/security/2017/05/the-hijacking-flaw-that-lurked-in-intel-chips-is-worse-than-anyone-thought" rel="nofollow">https://arstechnica.com/security/2017/05/the-hijacking-flaw-that-lurked-in-intel-chips-is-worse-than-anyone-thought</a></p>
<p>The bug was in the code to compare the two strings. It used the strncmp function that compares the first N characters of two strings:</p>
<p>strncmp(string1, string2, N)</p>
<p>This would work just fine for hashes sent by the browser, which are always 32 characters in length. Even if the password field is empty, it would compare the two strings, they wouldn&#8217;t match, and it would reject the empty password or invalid password.</p>
<p>The problem is what happens if you don&#8217;t use a browser, but you generate an invalid request manually or using a proxy to alter the response, sending an empty string instead of the 32 character hash. Then the compare code does this:</p>
<p>strncmp(&#8220;6629fae49393a05397450978507c4ef1&#8243;,&#8221;&#8221;,0)</p>
<p>This means the function will compare the first 0 characters between the two strings. So it is equivalent to:</p>
<p>strncmp(&#8220;&#8221;,&#8221;&#8221;,0)</p>
<p>Of course, two 0 length strings are equal, so it wrongfully concludes the hashes are equal.</p>
<p>What the programmer should have done is check if the hash coming from the browser has the correct length, 32 characters, before attempting to compare the two strings.</p>
<p>Or even better, the programmer should have used the proper string comparing function, strcmp, that already does that for you and you don&#8217;t need to supply a length parameter</p>
<p>The very fact that we&#8217;re debating if it was the handwork of a 3 letter agency or pure incompetence is a worrying sign of the times were in.</p>
<p>But to think that this flaw went on for 7 years&#8230; Were they just copying and pasting the AMT code from generation to generation? We&#8217;re talking about Intel here, the guys who seem to release a new processor with every full moon.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomi Engdahl</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1549385</link>
		<dc:creator><![CDATA[Tomi Engdahl]]></dc:creator>
		<pubDate>Fri, 02 Jun 2017 11:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1549385</guid>
		<description><![CDATA[The article at https://pentestmag.com/write-secure-code-cc-programming-languages/ says:

    Desist from using strcpy() and strcat(). Substitute them with strncpy() and strncat() instead

Using strcpy() and strcat() functions in C/C++ fail to limit the length of the input string to be copied or added to the output buffer. This way, they make the programs susceptible to buffer overflow attacks. As such, it’s better you use the more secure strncpy() and strncat() functions.

My comments on &quot;better you use the more secure strncpy() and strncat() functions&quot;:

The use of strncpy() and strncat() functions is a good idea when they are used correctly. 
If you use strncpy() incorrectly, it is not safer and can cause other type of security issues.
The strncpy() function pads the result string with zero (string termination character), but it 
does not guarantee that the end result is always null terminated. If input string has length of 
n or more, the output string contains n characters WITHOUT NULL termination. This can cause
serious problems when the string is used later!
So if you use strncpy(), you need to make sure that the output string is null terminated.

The strncat() function will always make null terminated string, which is good things.
The C library function char *strncat(char *dest, const char *src, size_t n) appends the string pointed to by src to the end of the string pointed to by dest up to n characters long. 
From https://stackoverflow.com/questions/41652122/does-strncat-always-null-terminate
Quoting C11, chapter §7.24.3.2, (emphasis mine)

    The strncat function appends not more than n characters (a null character and characters that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1. The initial character of s2 overwrites the null character at the end of s1. A terminating null character is always appended to the result.
and, the footnote
    Thus, the maximum number of characters that can end up in the array pointed to by s1 is strlen(s1)+n+1]]></description>
		<content:encoded><![CDATA[<p>The article at <a href="https://pentestmag.com/write-secure-code-cc-programming-languages/" rel="nofollow">https://pentestmag.com/write-secure-code-cc-programming-languages/</a> says:</p>
<p>    Desist from using strcpy() and strcat(). Substitute them with strncpy() and strncat() instead</p>
<p>Using strcpy() and strcat() functions in C/C++ fail to limit the length of the input string to be copied or added to the output buffer. This way, they make the programs susceptible to buffer overflow attacks. As such, it’s better you use the more secure strncpy() and strncat() functions.</p>
<p>My comments on &#8220;better you use the more secure strncpy() and strncat() functions&#8221;:</p>
<p>The use of strncpy() and strncat() functions is a good idea when they are used correctly.<br />
If you use strncpy() incorrectly, it is not safer and can cause other type of security issues.<br />
The strncpy() function pads the result string with zero (string termination character), but it<br />
does not guarantee that the end result is always null terminated. If input string has length of<br />
n or more, the output string contains n characters WITHOUT NULL termination. This can cause<br />
serious problems when the string is used later!<br />
So if you use strncpy(), you need to make sure that the output string is null terminated.</p>
<p>The strncat() function will always make null terminated string, which is good things.<br />
The C library function char *strncat(char *dest, const char *src, size_t n) appends the string pointed to by src to the end of the string pointed to by dest up to n characters long.<br />
From <a href="https://stackoverflow.com/questions/41652122/does-strncat-always-null-terminate" rel="nofollow">https://stackoverflow.com/questions/41652122/does-strncat-always-null-terminate</a><br />
Quoting C11, chapter §7.24.3.2, (emphasis mine)</p>
<p>    The strncat function appends not more than n characters (a null character and characters that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1. The initial character of s2 overwrites the null character at the end of s1. A terminating null character is always appended to the result.<br />
and, the footnote<br />
    Thus, the maximum number of characters that can end up in the array pointed to by s1 is strlen(s1)+n+1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomi Engdahl</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1548721</link>
		<dc:creator><![CDATA[Tomi Engdahl]]></dc:creator>
		<pubDate>Mon, 29 May 2017 08:11:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1548721</guid>
		<description><![CDATA[A Guide to the MISRA Coding Standard: What You Need to Know
http://www.techonline.com/electrical-engineers/education-training/tech-papers/4458213/A-Guide-to-the-MISRA-Coding-Standard-What-you-need-to-know

Compliance to MISRA is required across the automotive industry, but is rapidly taking root in many other industries.  Because MISRA was developed to provide a recognized standard to ensure safety critical systems are free of coding defects, more and more organizations in a variety of industries are demanding that software is developed in accordance with the MISRA standard.]]></description>
		<content:encoded><![CDATA[<p>A Guide to the MISRA Coding Standard: What You Need to Know<br />
<a href="http://www.techonline.com/electrical-engineers/education-training/tech-papers/4458213/A-Guide-to-the-MISRA-Coding-Standard-What-you-need-to-know" rel="nofollow">http://www.techonline.com/electrical-engineers/education-training/tech-papers/4458213/A-Guide-to-the-MISRA-Coding-Standard-What-you-need-to-know</a></p>
<p>Compliance to MISRA is required across the automotive industry, but is rapidly taking root in many other industries.  Because MISRA was developed to provide a recognized standard to ensure safety critical systems are free of coding defects, more and more organizations in a variety of industries are demanding that software is developed in accordance with the MISRA standard.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomi Engdahl</title>
		<link>https://www.epanorama.net/blog/2017/05/28/how-to-write-a-secure-code-in-cc-programming-languages/comment-page-1/#comment-1548709</link>
		<dc:creator><![CDATA[Tomi Engdahl]]></dc:creator>
		<pubDate>Mon, 29 May 2017 08:00:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.epanorama.net/newepa/?p=55788#comment-1548709</guid>
		<description><![CDATA[Avoiding The Top 10 Software Security Design Flaws
https://semiengineering.com/avoiding-the-top-10-software-security-design-flaws/

Why so many design flaws have remained on the list of top security issues for years, and how you can avoid them.

Avoiding the Top 10 Software Security Design Flaws
https://www.synopsys.com/software-integrity/resources/white-papers/top-10-software-design-flaws.html

The IEEE Center for Secure Design brought together some of the foremost experts in software security in a working group to tackle the issue of secure software design.

This whitepaper covers their findings]]></description>
		<content:encoded><![CDATA[<p>Avoiding The Top 10 Software Security Design Flaws<br />
<a href="https://semiengineering.com/avoiding-the-top-10-software-security-design-flaws/" rel="nofollow">https://semiengineering.com/avoiding-the-top-10-software-security-design-flaws/</a></p>
<p>Why so many design flaws have remained on the list of top security issues for years, and how you can avoid them.</p>
<p>Avoiding the Top 10 Software Security Design Flaws<br />
<a href="https://www.synopsys.com/software-integrity/resources/white-papers/top-10-software-design-flaws.html" rel="nofollow">https://www.synopsys.com/software-integrity/resources/white-papers/top-10-software-design-flaws.html</a></p>
<p>The IEEE Center for Secure Design brought together some of the foremost experts in software security in a working group to tackle the issue of secure software design.</p>
<p>This whitepaper covers their findings</p>
]]></content:encoded>
	</item>
</channel>
</rss>
