text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_alloca_memcpy_73b.cpp
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE806.label.xml
  Template File: sources-sink-73b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 121 Stack 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: 73 Data flow: data passed in a list from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <list>
  
  #include <wchar.h>
  
  using namespace std;
  
  namespace CWE121_Stack_Based_Buffer_Overflow__CWE806_wchar_t_alloca_memcpy_73
  {
  
  #ifndef OMITBAD
  
  void badSink(list<wchar_t *> dataList)
  {
      /* copy data out of dataList */
      wchar_t * data = dataList.back();
      {
          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);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(list<wchar_t *> dataList)
  {
      wchar_t * data = dataList.back();
      {
          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);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  