text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_dest_char_cat_62b.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_dest.label.xml
  Template File: sources-sink-62b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Allocate using new[] and set data pointer to a small buffer
   * GoodSource: Allocate using new[] and set data pointer to a large buffer
   * Sinks: cat
   *    BadSink : Copy string to data using strcat
   * Flow Variant: 62 Data flow: data flows using a C++ reference from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  namespace CWE122_Heap_Based_Buffer_Overflow__cpp_dest_char_cat_62
  {
  
  #ifndef OMITBAD
  
  void badSource(char * &data)
  {
      /* FLAW: Allocate using new[] and point data to a small buffer that is smaller than the large buffer used in the sinks */
      data = new char[50];
      data[0] = '\0'; /* null terminate */
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B() uses the GoodSource with the BadSink */
  void goodG2BSource(char * &data)
  {
      /* FIX: Allocate using new[] and point data to a large buffer that is at least as large as the large buffer used in the sink */
      data = new char[100];
      data[0] = '\0'; /* null terminate */
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  