The SAMATE Project Department of Homeland Security
Downloads:  Selected

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

Test Case IDDeprecated1322
Bad / GoodGoodGood 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
DescriptioniconFixed strcat
Filename

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

See the comments

Comment #1 :: Code is incorrect
Line 13 concatenates to the environment store, through str, instead of to the local buffer, buf. Also test at line 12 should be MAXSIZE, not MAXSIZE + 1. This case was replaced by case 2083.
Posted by Paul E. Black :: 2009-04-03 14:49:37

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