text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE617_Reachable_Assertion__fgets_51a.c
  Label Definition File: CWE617_Reachable_Assertion.label.xml
  Template File: sources-sink-51a.tmpl.c
  */
  /*
   * @description
   * CWE: 617 Reachable Assertion
   * BadSource: fgets Read data from the console using fgets()
   * GoodSource: Number greater than ASSERT_VALUE
   * Sink:
   *    BadSink : Assert if n is less than or equal to ASSERT_VALUE
   * Flow Variant: 51 Data flow: data passed as an argument from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <assert.h>
  
  #define ASSERT_VALUE 5
  
  #define CHAR_ARRAY_SIZE (3 * sizeof(data) + 2)
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE617_Reachable_Assertion__fgets_51b_badSink(int data);
  
  void CWE617_Reachable_Assertion__fgets_51_bad()
  {
      int data;
      /* Initialize data */
      data = -1;
      {
          char inputBuffer[CHAR_ARRAY_SIZE] = "";
          /* POTENTIAL FLAW: Read data from the console using fgets() */
          if (fgets(inputBuffer, CHAR_ARRAY_SIZE, stdin) != NULL)
          {
              /* Convert to int */
              data = atoi(inputBuffer);
          }
          else
          {
              printLine("fgets() failed.");
          }
      }
      CWE617_Reachable_Assertion__fgets_51b_badSink(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* good function declarations */
  void CWE617_Reachable_Assertion__fgets_51b_goodG2BSink(int data);
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2B()
  {
      int data;
      /* Initialize data */
      data = -1;
      /* FIX: Use a value greater than the assert value */
      data = ASSERT_VALUE+1;
      CWE617_Reachable_Assertion__fgets_51b_goodG2BSink(data);
  }
  
  void CWE617_Reachable_Assertion__fgets_51_good()
  {
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  /* Below is the main(). It is only used when building this testcase on
   * its own for testing or for building a binary to use in testing binary
   * analysis tools. It is not used when compiling all the testcases as one
   * application, which is how source code analysis tools are tested.
   */
  
  #ifdef INCLUDEMAIN
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      CWE617_Reachable_Assertion__fgets_51_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE617_Reachable_Assertion__fgets_51_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  