text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_65b.c
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
  Template File: sources-sink-65b.tmpl.c
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Allocate using malloc() and set data pointer to a small buffer
   * GoodSource: Allocate using malloc() and set data pointer to a large buffer
   * Sinks: loop
   *    BadSink : Copy int array to data using a loop
   * Flow Variant: 65 Data/control flow: data passed as an argument from one function to a function in a different source file called via a function pointer
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_65b_badSink(int * data)
  {
      {
          int source[100] = {0}; /* fill with 0's */
          {
              size_t i;
              /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
              for (i = 0; i < 100; i++)
              {
                  data[i] = source[i];
              }
              printIntLine(data[0]);
              free(data);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int_loop_65b_goodG2BSink(int * data)
  {
      {
          int source[100] = {0}; /* fill with 0's */
          {
              size_t i;
              /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
              for (i = 0; i < 100; i++)
              {
                  data[i] = source[i];
              }
              printIntLine(data[0]);
              free(data);
          }
      }
  }
  
  #endif /* OMITGOOD */
  