text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_wchar_t_loop_63b.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193.label.xml
  Template File: sources-sink-63b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Allocate memory for a string, but do not allocate space for NULL terminator
   * GoodSource: Allocate enough memory for a string and the NULL terminator
   * Sinks: loop
   *    BadSink : Copy array to data using a loop
   * Flow Variant: 63 Data flow: pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  /* MAINTENANCE NOTE: The length of this string should equal the 10 */
  #define SRC_STRING L"AAAAAAAAAA"
  
  namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_wchar_t_loop_63
  {
  
  #ifndef OMITBAD
  
  void badSink(wchar_t * * dataPtr)
  {
      wchar_t * data = *dataPtr;
      {
          wchar_t source[10+1] = SRC_STRING;
          size_t i, sourceLen;
          sourceLen = wcslen(source);
          /* Copy length + 1 to include NUL terminator from source */
          /* POTENTIAL FLAW: data may not have enough space to hold source */
          for (i = 0; i < sourceLen + 1; i++)
          {
              data[i] = source[i];
          }
          printWLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(wchar_t * * dataPtr)
  {
      wchar_t * data = *dataPtr;
      {
          wchar_t source[10+1] = SRC_STRING;
          size_t i, sourceLen;
          sourceLen = wcslen(source);
          /* Copy length + 1 to include NUL terminator from source */
          /* POTENTIAL FLAW: data may not have enough space to hold source */
          for (i = 0; i < sourceLen + 1; i++)
          {
              data[i] = source[i];
          }
          printWLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  