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:

  1. pszDest[MAX] = '\0'  should be pszDest[MAX-1] = '\0'; otherwise, we have a buffer overrun.
  2. 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.