text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_dest_struct_loop_61b.c
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_dest.label.xml
  Template File: sources-sink-61b.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 twoints array to data using a loop
   * Flow Variant: 61 Data flow: data returned from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  twoints * CWE122_Heap_Based_Buffer_Overflow__c_dest_struct_loop_61b_bad_source(twoints * data)
  {
      /* FLAW: Allocate and point data to a small buffer that is smaller than the large buffer used in the sinks */
      data = (twoints *)malloc(50*sizeof(twoints));
      return data;
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B() uses the GoodSource with the BadSink */
  twoints * CWE122_Heap_Based_Buffer_Overflow__c_dest_struct_loop_61b_goodG2B_source(twoints * data)
  {
      /* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */
      data = (twoints *)malloc(100*sizeof(twoints));
      return data;
  }
  
  #endif /* OMITGOOD */
  