text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_memcpy_64b.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE805.string.label.xml
  Template File: sources-sink-64b.tmpl.c
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Set data pointer to the bad buffer
   * GoodSource: Set data pointer to the good buffer
   * Sinks: memcpy
   *    BadSink : Copy string to data using memcpy
   * Flow Variant: 64 Data flow: void pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_memcpy_64b_badSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      wchar_t * * dataPtr = (wchar_t * *)dataVoidPtr;
      /* dereference dataPtr into data */
      wchar_t * data = (*dataPtr);
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with L'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          memcpy(data, source, 100*sizeof(wchar_t));
          data[100-1] = L'\0'; /* Ensure the destination buffer is null terminated */
          printWLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_wchar_t_alloca_memcpy_64b_goodG2BSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      wchar_t * * dataPtr = (wchar_t * *)dataVoidPtr;
      /* dereference dataPtr into data */
      wchar_t * data = (*dataPtr);
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with L'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          memcpy(data, source, 100*sizeof(wchar_t));
          data[100-1] = L'\0'; /* Ensure the destination buffer is null terminated */
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  