text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83_goodG2B.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806.label.xml
  Template File: sources-sink-83_goodG2B.tmpl.cpp
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Initialize data as a large string
   * GoodSource: Initialize data as a small string
   * Sinks: memcpy
   *    BadSink : Copy data to string using memcpy
   * Flow Variant: 83 Data flow: data passed to class constructor and destructor by declaring the class object on the stack
   *
   * */
  #ifndef OMITGOOD
  
  #include "std_testcase.h"
  #include "CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83.h"
  
  namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83
  {
  CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83_goodG2B::CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83_goodG2B(wchar_t * dataCopy)
  {
      data = dataCopy;
      /* FIX: Initialize data as a small buffer that as small or smaller than the small buffer used in the sink */
      wmemset(data, L'A', 50-1); /* fill with L'A's */
      data[50-1] = L'\0'; /* null terminate */
  }
  
  CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83_goodG2B::~CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_wchar_t_memcpy_83_goodG2B()
  {
      {
          wchar_t dest[50] = L"";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          memcpy(dest, data, wcslen(data)*sizeof(wchar_t));
          dest[50-1] = L'\0'; /* Ensure the destination buffer is null terminated */
          printWLine(data);
          delete [] data;
      }
  }
  }
  #endif /* OMITGOOD */
  