The SAMATE Project Department of Homeland Security
Downloads:  Selected

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

Test Case IDCandidate89
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorFortify
LanguageC
Type of test caseSource Code
Input stringN/A
Expected OutputN/A
InstructionsN/A
Submission date2006-01-04
DescriptioniconAn ad-hoc string copy without bounds check overflows a stack buffer. PLOVER: BUFF.OVER
Filename

There is no comments :: Submit a comment :: RSS

>./ahscpy-bad1.c
  1. /*PLOVER: BUFF.OVER */
  2.  
  3. /*
  4. Description: An ad-hoc string copy without bounds check overflows a stack buffer.
  5. Keywords: Size0 Complex0 BufferOverflow Stack AdHocCopy Unbounded
  6. ValidArg: "a"*30
  7. InvalidArg: "a"*100
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #define MAXSIZE    40
  14. void
  15. test(char *str)
  16. {
  17.         char buf[MAXSIZE], *p;
  18.  
  19.         p = buf;
  20.         while((*p++ = *str++))        /* BAD */
  21.                 continue;
  22.         printf("result: %s\n", buf);
  23. }
  24.  
  25. int
  26. main(int argc, char **argv)
  27. {
  28.         char *userstr;
  29.  
  30.         if(argc > 1) {
  31.                 userstr = argv[1];
  32.                 test(userstr);
  33.         }
  34.         return 0;
  35. }
  36.