text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_alloca_memcpy_74b.cpp
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE193.label.xml
  Template File: sources-sink-74b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Point data to a buffer that does not have space for a NULL terminator
   * GoodSource: Point data to a buffer that includes space for a NULL terminator
   * Sinks: memcpy
   *    BadSink : Copy string to data using memcpy()
   * Flow Variant: 74 Data flow: data passed in a map from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <map>
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  /* MAINTENANCE NOTE: The length of this string should equal the 10 */
  #define SRC_STRING L"AAAAAAAAAA"
  
  using namespace std;
  
  namespace CWE121_Stack_Based_Buffer_Overflow__CWE193_wchar_t_alloca_memcpy_74
  {
  
  #ifndef OMITBAD
  
  void badSink(map<int, wchar_t *> dataMap)
  {
      /* copy data out of dataMap */
      wchar_t * data = dataMap[2];
      {
          wchar_t source[10+1] = SRC_STRING;
          /* Copy length + 1 to include NUL terminator from source */
          /* POTENTIAL FLAW: data may not have enough space to hold source */
          memcpy(data, source, (wcslen(source) + 1) * sizeof(wchar_t));
          printWLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, wchar_t *> dataMap)
  {
      wchar_t * data = dataMap[2];
      {
          wchar_t source[10+1] = SRC_STRING;
          /* Copy length + 1 to include NUL terminator from source */
          /* POTENTIAL FLAW: data may not have enough space to hold source */
          memcpy(data, source, (wcslen(source) + 1) * sizeof(wchar_t));
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  