The SAMATE Project Department of Homeland Security
Downloads:  Selected

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

Test Case IDCandidate39
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-28
DescriptioniconRace conditions occur frequently in signal handlers, since they are asynchronous actions. These race conditions may have any number of root-causes and symptoms. (from TCCLASP-5_4_7_10)
Filename
Flaw
  • (?) CWE-362: Race Condition at line 18,19

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

>./Race_condition_in_signal_handler.c
  1. #include <signal.h>
  2. #include <syslog.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. void *global1, *global2;
  6. char *what;
  7. void sh(int dummy) {
  8. syslog(LOG_NOTICE,"%s\n",what);
  9. free(global2);
  10. free(global1);
  11. sleep(10);
  12. exit(0);
  13. }
  14. int main(int argc,char* argv[]) {
  15. what=argv[1];
  16. global1=strdup(argv[2]);
  17. global2=malloc(340);
  18. signal(SIGHUP,sh);
  19. signal(SIGTERM,sh);
  20. sleep(10);
  21. exit(0);
  22. }
  23.  
  24.