title: Why is this code vulnerable to buffer overflow attacks?
body: <pre><code>int func(char* str)
  {
     char buffer[100];
     unsigned short len = strlen(str);
  
     if(len &gt;= 100)
     {
          return (-1);
     }
  
     strncpy(buffer,str,strlen(str));
     return 0;
  }
  </code></pre>
  
  <p>This code is vulnerable to a buffer overflow attack, and I'm trying to figure out why. I'm thinking it has to do with <code>len</code> being declared a <code>short</code> instead of an <code>int</code>, but I'm not really sure.</p>
  
  <p><strong>Any ideas?</strong></p>