Monday, July 18, 2005 1:33 PM
rsamona
Spot the Bug - July 18, 2005
Alright all - here is the bug for July 18. This should be an easy one to find. Any takers? :-)
#define MAX (50)
char szDest[MAX];
strncpy(szDest,pszSrc,MAX);
pszDest[MAX] = '\0';
Solution:
Nice job on this one, everyone! As most of you found out, there are the two bugs in the code:
- pszDest[MAX] = '\0' should be pszDest[MAX-1] = '\0'; otherwise, we have a buffer overrun.
- pszDest is not declared in this code. – accidental typo :)
For more information on buffer overruns, visit the MSDN Security Developer Center and read Fix Those Buffer Overruns! by Michael Howard.