<?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>Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx</link><description>It seems like more and more developers are making security mistakes when dealing with sockets. See if you can Spot the Bug. void Socket_Setup(void) { WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD( 2, 2 ); ::WSAStartup(wVersionRequested,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#550962</link><pubDate>Tue, 14 Mar 2006 07:40:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:550962</guid><dc:creator>Dean Harding</dc:creator><description>The only thing I can spot is that it's assuming the client has null-terminated the string. That is, it doesn't use the value returned by ::recv.&lt;br&gt;&lt;br&gt;But this is more than just a security bug. The networking layer can split the underlying packets, and if one of those packets is delayed, ::recv may only return part of the data (subsequent calls to ::recv would then return the rest of the data that was delayed).</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#550967</link><pubDate>Tue, 14 Mar 2006 07:52:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:550967</guid><dc:creator>Dean Harding</dc:creator><description>Oh yeah, the other point is that the ::listen can be the one to fail with WSAEADDRINUSE when you use ADDR_ANY in the ::bind. And you don't check the return value from ::listen. But if that happens, ::accept would give an error WSAEINVAL as would the subsequent ::recv.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#550977</link><pubDate>Tue, 14 Mar 2006 08:16:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:550977</guid><dc:creator>Ed Kaim</dc:creator><description>To add to Dean's comment, not using the return value can cause interesting results after successive calls, even with valid data and no malicious intent. Let's say Socket_Setup is called and one person connects, sends valid data (NULL-terminated and &amp;lt; 1024 bytes), disconnects, it's printed, and then the method returns. Next, Socket_Setup is immediately called again and set up with the same exact stack pointer. However, on the second request, the network client exits without sending any data (such as by losing the connection due to latency). Theoretically, strData would still contain the same data it held on the last iteration, resulting in the same string being printed to the screen. There is a definite security bug here in that it would indicate the first set of data was repeated when it really wasn't. In this specific case it would just impact logging, although in a credit card system it could result in multiple charges, in a voting system it could mean extra votes, etc.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#551383</link><pubDate>Tue, 14 Mar 2006 21:40:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:551383</guid><dc:creator>Dinhduy Tran</dc:creator><description>One more comment, if the strData contains more than one strings (NULL-terminated) then printf only print out the first string, other strings in the buffer will be lost. &amp;nbsp;</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#552608</link><pubDate>Thu, 16 Mar 2006 09:31:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:552608</guid><dc:creator>Hariharan Jayaraman</dc:creator><description>1&amp;gt; No Error check done on accept, incase of a failure invalid socket is returned and the same has been used by recv. same is the case with listen.&lt;br&gt;&lt;br&gt;2&amp;gt; The code does not check the return value of recv, and blindly prints the strData, by default locals char types have no gaurantee of having null termination, hence this could print the stack and eventually segfault&lt;br&gt;&lt;br&gt;3&amp;gt; Even if error checks are done, specific care needs to be taken as it is a stream socket, like for example incase of stream sockets , even if data is there in the buffer, during the call if there is connection reset received than recv would return with zero bytes read.&lt;br&gt;&lt;br&gt;4&amp;gt; &amp;nbsp;if(0 != iFail)&lt;br&gt; &amp;nbsp;{&lt;br&gt; &amp;nbsp; &amp;nbsp;dwErr = ::WSAGetLastError();&lt;br&gt; &amp;nbsp; &amp;nbsp;printf(&amp;quot;\n\t Error occured.\n&amp;quot;);&lt;br&gt; &amp;nbsp; &amp;nbsp;return;&lt;br&gt; &amp;nbsp;}&lt;br&gt; &amp;nbsp;&lt;br&gt; &amp;nbsp;In this error condition, no call to WSACleanup is done, this will lead to resource usage in the networking subsystem for the application.&lt;br&gt;&lt;br&gt;5&amp;gt; Minor,Same thing above dwErr is not used anywhere.&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#552764</link><pubDate>Thu, 16 Mar 2006 15:05:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:552764</guid><dc:creator>Appa Desai</dc:creator><description>Return value of WSAStartUp itself is not checked.&lt;br&gt;moreover to ensure WSACleanup is called before every exit from the function, there could be a AutoRelease class whose destructor should have a WSACleanup call.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#552950</link><pubDate>Thu, 16 Mar 2006 19:19:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:552950</guid><dc:creator>Ranju. V</dc:creator><description>Adding to all that has been observed so far, &amp;quot;recv&amp;quot; returns the number of bytes read from the socket. &amp;nbsp;The program should probably use that information to ensure that a null terminator has been set appropriately. &amp;nbsp;Something like:&lt;br&gt;&lt;br&gt; len = recv( sClient, strData, 1023, 0 );&lt;br&gt; // handle error if &amp;quot;len&amp;quot; equals SOCKET_ERROR&lt;br&gt; strData[len] = '\0';</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#553459</link><pubDate>Fri, 17 Mar 2006 07:45:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:553459</guid><dc:creator>Dinesh</dc:creator><description>Theer are two major bugs in the code.&lt;br&gt;1) If the Bind fails we return without doing the Socket cleanup which is usually done by WSACleanup.&lt;br&gt;2) The array 'char strData[1024]' is not initialized. This can be dangerous and can be a security threat.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#553482</link><pubDate>Fri, 17 Mar 2006 08:41:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:553482</guid><dc:creator>devi</dc:creator><description>I think, the same bug has been spotted already and the solution has been identified&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/rsamona/archive/2005/11/28/497712.aspx"&gt;http://blogs.msdn.com/rsamona/archive/2005/11/28/497712.aspx&lt;/a&gt;</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#553684</link><pubDate>Fri, 17 Mar 2006 16:02:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:553684</guid><dc:creator>Jayant Dusane</dc:creator><description>While result of failing the bind operation no ::WSACleanup() is called.&lt;br&gt;Also the strData for recv is not initialized with NULL.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#555311</link><pubDate>Mon, 20 Mar 2006 08:06:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:555311</guid><dc:creator>Murtaza Ghiya</dc:creator><description>What I have observed with sockets on Windows is that the recv is not a blocking call and need not necessarily return the no. of bytes it has been asked to recieve. So it is very important to actually check if 1024 bytes were actually read and make the buffer null-terminated. What we usually do is write a wrapper over the recv() call to actually receive the expected no. of bytes.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#557366</link><pubDate>Wed, 22 Mar 2006 02:51:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:557366</guid><dc:creator>athul h</dc:creator><description>int iFail =::bind(sTCPServer, (struct sockaddr*)&amp;amp;saTCPServAddr, len);&lt;br&gt; &amp;nbsp;DWORD dwErr;&lt;br&gt; &amp;nbsp;if(0 != iFail)&lt;br&gt;&lt;br&gt;&lt;br&gt;it ll never bezero</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#557600</link><pubDate>Wed, 22 Mar 2006 08:01:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:557600</guid><dc:creator>gaurav</dc:creator><description>Return value of WSAStartUp itself is not checked. &lt;br&gt;moreover to ensure WSACleanup is called before every exit from the function, there could be a AutoRelease class whose destructor should have a WSACleanup call.&lt;br&gt;&lt;br&gt;&lt;br&gt;and &lt;br&gt;&lt;br&gt;While result of failing the bind operation no ::WSACleanup() is called. &lt;br&gt;Also the strData for recv is not initialized with NULL. </description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#557604</link><pubDate>Wed, 22 Mar 2006 08:14:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:557604</guid><dc:creator>Danda Ramesh Kumar</dc:creator><description>The code does not checking &amp;nbsp;the return value of recv.&lt;br&gt;incase of a failure invalid socket is returned and the same has been used by recv.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#557820</link><pubDate>Wed, 22 Mar 2006 14:13:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:557820</guid><dc:creator>Black Horse</dc:creator><description>Microsoft and security? You must be joking. If you are looking for security, abandon Microsoft. Down load any distribution of Linux.&lt;br&gt;&lt;br&gt;When the whole operating system and all Microsoft development / business products are buggy, have hole and have back doors (for NSA, US Gov), you must be really off your rockers trying to fool yourself with this exercise.&lt;br&gt;&lt;br&gt;No, you wont put it on the site, too afraid.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#558559</link><pubDate>Thu, 23 Mar 2006 04:26:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:558559</guid><dc:creator>Nagendra</dc:creator><description>Considering these lines&lt;br&gt;1. char strData[1024];&lt;br&gt;2. ::recv(sClient, strData, 1024, 0);&lt;br&gt;3. &amp;nbsp;printf(&amp;quot;\n\nRealServer--Data from client --- %s ---&amp;quot;, strData);&lt;br&gt;&lt;br&gt;It think a hacker can override the no 1024 in the line 2 above and this can push his own code to execute since the buffer strData just has 1024 bytes to store , and all the data overflown might become executable code.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#558807</link><pubDate>Thu, 23 Mar 2006 14:01:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:558807</guid><dc:creator>~!@#$%^&amp;*()</dc:creator><description>'</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#558808</link><pubDate>Thu, 23 Mar 2006 14:03:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:558808</guid><dc:creator>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</dc:creator><description>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#562081</link><pubDate>Mon, 27 Mar 2006 19:30:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:562081</guid><dc:creator>Karthik Narasimhan</dc:creator><description>Hi,&lt;br&gt;&lt;br&gt; &amp;nbsp; &amp;nbsp; I found the following 2 items as probable bugs in this function.&lt;br&gt;1] INADDR_ANY :-&lt;br&gt; When receiving, a socket bound to this address receives packets from all interfaces show have used a specific ip address rather.&lt;br&gt;&lt;br&gt;2] Port # 5678 &lt;br&gt;A known exploit is already available as described below:&lt;br&gt;Port 5678 &lt;br&gt;(TCP+UDP) A port for remote execution using the crexd/srexd services. &lt;br&gt;(TCP+UDP) A frequent port some picks at random. &lt;br&gt;&lt;br&gt;(TCP+UDP) Port 5678 was originally specified for the PPTP protocol, but when the standard was ratified, port 1723 was chosen instead. &lt;br&gt;&lt;br&gt;(TCP) Port 5678 is the default port for the com.hp.util.rcat Java package (from Hewlett-Packard). This is a simple debugging package. &lt;br&gt;&lt;br&gt;(UDP) osagent communication &lt;br&gt;&lt;br&gt;That's all from my side.&lt;br&gt;Thanks &amp;amp; have a nice day.&lt;br&gt;From,&lt;br&gt;Karthik Narasimhan</description></item><item><title>MSDN Flash Ireland Resources - 31 Mar 06</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#566004</link><pubDate>Fri, 31 Mar 2006 19:17:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:566004</guid><dc:creator>Robert Burke's Weblog</dc:creator><description>Web Resources&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;[.NET Framework] GotDotNet CodeGallery &lt;br&gt;Share, find, download and discuss evolving...</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#567942</link><pubDate>Tue, 04 Apr 2006 10:11:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:567942</guid><dc:creator>Manoj Dalei</dc:creator><description>Hi,&lt;br&gt; &amp;nbsp; &amp;nbsp;here is the revised program.&lt;br&gt;&lt;br&gt;void Socket_Setup(void)&lt;br&gt;{&lt;br&gt; &amp;nbsp;WORD wVersionRequested;&lt;br&gt; &amp;nbsp;WSADATA wsaData;&lt;br&gt; &amp;nbsp;wVersionRequested = MAKEWORD( 2, 2 );&lt;br&gt; &lt;br&gt; if( ::WSAStartup(wVersionRequested, &amp;amp;wsaData) !=0)&lt;br&gt; &amp;nbsp;{&lt;br&gt;	dwErr = ::WSAGetLastError();&lt;br&gt; &amp;nbsp; &amp;nbsp;	printf(&amp;quot;\n\t Error occured.\n&amp;quot;);&lt;br&gt; &amp;nbsp; 	return;&lt;br&gt; &amp;nbsp;}&lt;br&gt; &amp;nbsp; float socklib_ver; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* socket dll version */&lt;br&gt; &amp;nbsp; socklib_ver = HIBYTE( wsaData.wVersion ) / 10.0;&lt;br&gt; &amp;nbsp; socklib_ver += LOBYTE( wsaData.wVersion );&lt;br&gt;&lt;br&gt; &amp;nbsp; if ( socklib_ver &amp;lt; 2.0 )&lt;br&gt; &amp;nbsp; { &amp;nbsp; &amp;nbsp; &lt;br&gt; &amp;nbsp; &amp;nbsp;::WSACleanup(); /* clean up before exit */&lt;br&gt; &amp;nbsp; &amp;nbsp; return ;&lt;br&gt; &amp;nbsp; } &amp;nbsp; &amp;nbsp;&lt;br&gt; &amp;nbsp;&lt;br&gt; &amp;nbsp;SOCKET sTCPServer = ::socket(AF_INET, SOCK_STREAM, 0);&lt;br&gt; &amp;nbsp;if(sTCPServer == INVALID_SOCKET)&lt;br&gt; &amp;nbsp;{&lt;br&gt; &amp;nbsp; &amp;nbsp; ::WSACleanup(); /* clean up before exit */&lt;br&gt; &amp;nbsp; &amp;nbsp; return ;&lt;br&gt; &amp;nbsp;}&lt;br&gt; &amp;nbsp;struct sockaddr_in saTCPServAddr;&lt;br&gt; &amp;nbsp;saTCPServAddr.sin_family = AF_INET;&lt;br&gt; &amp;nbsp;saTCPServAddr.sin_addr.S_un.S_addr = ::htonl(INADDR_ANY);&lt;br&gt; &amp;nbsp;saTCPServAddr.sin_port = ::htons(5678);&lt;br&gt; &amp;nbsp;int len = sizeof(saTCPServAddr);&lt;br&gt; &lt;br&gt; &amp;nbsp;int iFail =::bind(sTCPServer, (struct sockaddr*)&amp;amp;saTCPServAddr, len);&lt;br&gt; &amp;nbsp;DWORD dwErr;&lt;br&gt; &amp;nbsp;if(0 != iFail)&lt;br&gt; &amp;nbsp;{&lt;br&gt; &amp;nbsp; &amp;nbsp;dwErr = ::WSAGetLastError();&lt;br&gt; &amp;nbsp; &amp;nbsp;printf(&amp;quot;\n\t Error occured.\n&amp;quot;);&lt;br&gt; &amp;nbsp; &amp;nbsp;::closesocket(sTCPServer);&lt;br&gt; &amp;nbsp; &amp;nbsp;::WSACleanup(); /* clean up before exit */&lt;br&gt; &amp;nbsp; &amp;nbsp;return;&lt;br&gt; &amp;nbsp;} &lt;br&gt;&lt;br&gt; &amp;nbsp;iFail = ::listen(sTCPServer, 2);&lt;br&gt; &lt;br&gt; &amp;nbsp;struct sockaddr_in saClient;&lt;br&gt; &amp;nbsp;int iClsize = sizeof(saClient);&lt;br&gt; &amp;nbsp;SOCKET sClient = ::accept(sTCPServer, (struct sockaddr*)&amp;amp;saClient ,&amp;amp;iClsize);&lt;br&gt; &amp;nbsp;if(sClient == INVALID_SOCKET)&lt;br&gt; &amp;nbsp;{&lt;br&gt; &amp;nbsp; &amp;nbsp; ::closesocket(sTCPServer);&lt;br&gt; &amp;nbsp; &amp;nbsp; ::WSACleanup(); /* clean up before exit */&lt;br&gt; &amp;nbsp; &amp;nbsp; return ;&lt;br&gt; &amp;nbsp;}&lt;br&gt; &amp;nbsp;char strData[1024];&lt;br&gt; &amp;nbsp;u_long arg = 0;&lt;br&gt; if (::ioctlsocket(sClient, FIONREAD, &amp;amp;arg) == 0) &lt;br&gt; {&lt;br&gt; &amp;nbsp; if (arg &amp;gt; 0)&lt;br&gt; &amp;nbsp; {&lt;br&gt;	if (arg &amp;gt; 1024)arg = 1024;&lt;br&gt;	int rv = ::recv(sClient, strData, arg, 0);&lt;br&gt;	printf(&amp;quot;\n\nRealServer--Data from client --- %s ---&amp;quot;, strData);&lt;br&gt; &amp;nbsp; }&lt;br&gt; &amp;nbsp;} &amp;nbsp;&lt;br&gt; &amp;nbsp;::shutdown(sTCPServer, SD_BOTH); &lt;br&gt; &amp;nbsp;::WSACleanup(); &lt;br&gt; &amp;nbsp;return;&lt;br&gt;}</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#568039</link><pubDate>Tue, 04 Apr 2006 14:32:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:568039</guid><dc:creator>Ashish Singhal</dc:creator><description>The problem I see is with the size of sClient i.e. 1024. The socket will wait for a client to connect and let it send a buffer. Assuming null termination of the string has been taken care of. &lt;br&gt;If the client sends a buffer larger than 1024 bytes, the code will terminate abruptly and result in a crash, very coomonly referred to as &amp;quot;Buffer overflow&amp;quot;. These attacks are primarily used for Denial of service scenario's.&lt;br&gt;We should add a check i.e. if the received bytes (value returned by recv) is greater than the buffer we allocated the bytes be dropped or the buffer size is increased correspondingly.</description></item><item><title>re: Spot the Bug - March 13, 2006</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#573221</link><pubDate>Tue, 11 Apr 2006 12:46:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:573221</guid><dc:creator>TSS</dc:creator><description>Bugs? Bugs! =)&lt;br&gt;5 bugs, 1 critical and one potentional dangerous condition&lt;br&gt;I'm review code and add some IMHO useful comments =)&lt;br&gt;&lt;br&gt;void Socket_Setup(void)&lt;br&gt;{&lt;br&gt;	WORD wVersionRequested;&lt;br&gt;	WSADATA wsaData;&lt;br&gt;	wVersionRequested = MAKEWORD( 2, 2 );&lt;br&gt;	// BUG_1: Return value check&lt;br&gt;	if (0 != ::WSAStartup(wVersionRequested, &amp;amp;wsaData))&lt;br&gt;		// handle error here...&lt;br&gt;	&lt;br&gt;	SOCKET sTCPServer = ::socket(AF_INET, SOCK_STREAM, 0);&lt;br&gt;	// BUG_2: Return value check&lt;br&gt;	if (INVALID_SOCKET == sTCPServer)&lt;br&gt;		// handle error here...&lt;br&gt;&lt;br&gt;	struct sockaddr_in saTCPServAddr;&lt;br&gt;	saTCPServAddr.sin_family = AF_INET;&lt;br&gt;	saTCPServAddr.sin_addr.S_un.S_addr = ::htonl(INADDR_ANY);&lt;br&gt;	saTCPServAddr.sin_port = ::htons(5678);&lt;br&gt;	int len = sizeof(saTCPServAddr);&lt;br&gt;	&lt;br&gt;	int iFail =::bind(sTCPServer, (struct sockaddr*)&amp;amp;saTCPServAddr, len);&lt;br&gt;	DWORD dwErr;&lt;br&gt;	// if(0 != iFail)&lt;br&gt;	// BUG_3: Check for SOCKET_ERROR, not for 0&lt;br&gt;	if (SOCKET_ERROR == iFail)&lt;br&gt;	{&lt;br&gt;		dwErr = ::WSAGetLastError();&lt;br&gt;		printf(&amp;quot;\n\t Error occured.\n&amp;quot;);&lt;br&gt;		return;&lt;br&gt;	}&lt;br&gt;	&lt;br&gt;	// BUG_4: Return value check&lt;br&gt;	iFail = ::listen(sTCPServer, 2);&lt;br&gt;	if (SOCKET_ERROR == iFail)&lt;br&gt;		// handle error here&lt;br&gt;	&lt;br&gt;	struct sockaddr_in saClient;&lt;br&gt;	int iClsize = sizeof(saClient);&lt;br&gt;	SOCKET sClient = ::accept(sTCPServer, (struct sockaddr*)&amp;amp;saClient ,&amp;amp;iClsize);&lt;br&gt;	// BUG_5: Return value check&lt;br&gt;	if (INVALID_SOCKET == sClient)&lt;br&gt;		// handle error here&lt;br&gt;&lt;br&gt;	// BUG_5: Critical !!!. Buffer overflow here!&lt;br&gt;	char strData[1024];&lt;br&gt;	// ::recv(sClient, strData, 1024, 0);&lt;br&gt;	int nBytesReceived = ::recv (sClient, strData, &lt;br&gt;		sizeof (strData) - 1, 0);				// !!!&lt;br&gt;	if (nBytesReceived &amp;gt;= 0)					// !!!&lt;br&gt;		strData[nBytesReceived] = '\0';			// !!!&lt;br&gt;&lt;br&gt;	// Minor bug: trying to dump out binary information on console...&lt;br&gt;	printf(&amp;quot;\n\nRealServer--Data from client --- %s ---&amp;quot;, strData);&lt;br&gt;	&lt;br&gt;	::shutdown (sTCPServer, SD_BOTH);&lt;br&gt;&lt;br&gt;	// BUG_6: Resourses leak:&lt;br&gt;	closesocket (sClient);&lt;br&gt;	closesocket (sTCPServer);&lt;br&gt;&lt;br&gt;	::WSACleanup();&lt;br&gt;	&lt;br&gt;	return;&lt;br&gt;}&lt;br&gt;</description></item><item><title> Spot the Bug Spot the Bug March 13 2006 | adirondack chairs</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#9783517</link><pubDate>Fri, 19 Jun 2009 12:00:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9783517</guid><dc:creator> Spot the Bug Spot the Bug March 13 2006 | adirondack chairs</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://adirondackchairshub.info/story.php?id=3062"&gt;http://adirondackchairshub.info/story.php?id=3062&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Spot the Bug Spot the Bug March 13 2006 | patio cushions</title><link>http://blogs.msdn.com/rsamona/archive/2006/03/13/550949.aspx#9784698</link><pubDate>Fri, 19 Jun 2009 13:10:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9784698</guid><dc:creator> Spot the Bug Spot the Bug March 13 2006 | patio cushions</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://patiocushionsource.info/story.php?id=1846"&gt;http://patiocushionsource.info/story.php?id=1846&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>