text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memcpy_72b.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml
  Template File: sources-sink-72b.tmpl.cpp
  */
  /*
   * @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: memcpy
   *    BadSink : Copy int64_t array to data using memcpy
   * Flow Variant: 72 Data flow: data passed in a vector from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <vector>
  
  using namespace std;
  
  namespace CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memcpy_72
  {
  
  #ifndef OMITBAD
  
  void badSink(vector<int64_t *> dataVector)
  {
      /* copy data out of dataVector */
      int64_t * data = dataVector[2];
      {
          int64_t source[100] = {0}; /* fill with 0's */
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memcpy(data, source, 100*sizeof(int64_t));
          printLongLongLine(data[0]);
          free(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(vector<int64_t *> dataVector)
  {
      int64_t * data = dataVector[2];
      {
          int64_t source[100] = {0}; /* fill with 0's */
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memcpy(data, source, 100*sizeof(int64_t));
          printLongLongLine(data[0]);
          free(data);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  