The SAMATE Project Department of Homeland Security
Downloads:  Selected

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

Test Case IDCandidate8
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorSecureSoftware
LanguageC
Type of test caseSource Code
Input stringN/A
Expected OutputN/A
InstructionsN/A
Submission date2005-10-26
DescriptioniconFreeing or deleting the same memory chunk twice may - when combined with other flaws - result in a write-what-where condition. (from TCCLASP-5_2_20_10)
Filename
Flaw
  • (?) CWE-123: Write-what-where Condition 

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

>./Doubly_freeing_memory.c
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #define BUFSIZE1 512
  4. #define BUFSIZE2 ((BUFSIZE1/2) - 8)
  5. int main(int argc, char **argv) {
  6. char *buf1R1;
  7. char *buf2R1;
  8. char *buf1R2;
  9. buf1R1 = (char *) malloc(BUFSIZE2);
  10. buf2R1 = (char *) malloc(BUFSIZE2);
  11. free(buf1R1);
  12. free(buf2R1);
  13. buf1R2 = (char *) malloc(BUFSIZE1);
  14. strncpy(buf1R2, argv[1], BUFSIZE1-1);
  15. free(buf2R1);
  16. free(buf1R2);
  17. }
  18.  
  19.  
  20.  
  21.  
  22.