text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE190_Integer_Overflow__int_fgets_multiply_63a.c
  Label Definition File: CWE190_Integer_Overflow__int.label.xml
  Template File: sources-sinks-63a.tmpl.c
  */
  /*
   * @description
   * CWE: 190 Integer Overflow
   * BadSource: fgets Read data from the console using fgets()
   * GoodSource: Set data to a small, non-zero number (two)
   * Sinks: multiply
   *    GoodSink: Ensure there will not be an overflow before multiplying data by 2
   *    BadSink : If data is positive, multiply by 2, which can cause an overflow
   * Flow Variant: 63 Data flow: pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #define CHAR_ARRAY_SIZE (3 * sizeof(data) + 2)
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE190_Integer_Overflow__int_fgets_multiply_63b_badSink(int * dataPtr);
  
  void CWE190_Integer_Overflow__int_fgets_multiply_63_bad()
  {
      int data;
      /* Initialize data */
      data = 0;
      {
          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.");
          }
      }
      CWE190_Integer_Overflow__int_fgets_multiply_63b_badSink(&data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE190_Integer_Overflow__int_fgets_multiply_63b_goodG2BSink(int * data);
  
  static void goodG2B()
  {
      int data;
      /* Initialize data */
      data = 0;
      /* FIX: Use a small, non-zero value that will not cause an integer overflow in the sinks */
      data = 2;
      CWE190_Integer_Overflow__int_fgets_multiply_63b_goodG2BSink(&data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE190_Integer_Overflow__int_fgets_multiply_63b_goodB2GSink(int * data);
  
  static void goodB2G()
  {
      int data;
      /* Initialize data */
      data = 0;
      {
          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.");
          }
      }
      CWE190_Integer_Overflow__int_fgets_multiply_63b_goodB2GSink(&data);
  }
  
  void CWE190_Integer_Overflow__int_fgets_multiply_63_good()
  {
      goodG2B();
      goodB2G();
  }
  
  #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()...");
      CWE190_Integer_Overflow__int_fgets_multiply_63_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE190_Integer_Overflow__int_fgets_multiply_63_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  