The SAMATE Project Department of Homeland Security
Downloads:  Selected

Back to the previous page...Back to the previous page

Test Case IDDeprecated1319
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
Contributorsindelar
LanguageC
Type of test caseSource Code
Input stringN/A
Expected OutputN/A
InstructionsN/A
Submission date2006-01-27
DescriptioniconNo bounds checking on buffer. PLOVER: BUFF.OVER
Filename

There is 1 comment :: Submit a comment :: RSS

See the comments

Comment #1 :: Code has other errors
Line 20 concatenates to the environment store, through str, instead of to the local buffer, buf. This case was replaced by case 2081
Posted by Paul E. Black :: 2009-04-03 14:55:19

>./strcat-bad1.c
  1. /*
  2.   PLOVER: BUFF.OVER
  3. */
  4.  
  5. /*
  6.         No bounds checking
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. #define MAXSIZE 40
  13.  
  14. void test(char *str, char *str2){
  15.         char buf[MAXSIZE];
  16.         if(strlen(str) < MAXSIZE)
  17.                 strcpy(buf, str);
  18.         else
  19.                 return;
  20.         strcat(str, str2);
  21.         printf("results: %s\n",str );
  22. }
  23.  
  24. int main(int argc, char **argv){
  25.         char *userstr;
  26.         char *userstr2;
  27.         if(argc > 2){
  28.                 userstr = argv[1];
  29.                 userstr2 = argv[2];
  30.                 test(userstr,userstr2);
  31.         }
  32.         return 0;
  33. }
  34.