text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__src_wchar_t_alloca_memmove_54e.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__src.string.label.xml
  Template File: sources-sink-54e.tmpl.c
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Initialize data as a large string
   * GoodSource: Initialize data as a small string
   * Sink: memmove
   *    BadSink : Copy data to string using memmove
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__src_wchar_t_alloca_memmove_54e_bad_sink(wchar_t * data)
  {
      {
          wchar_t dest[50] = L"";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          memmove(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 CWE121_Stack_Based_Buffer_Overflow__src_wchar_t_alloca_memmove_54e_goodG2B_sink(wchar_t * data)
  {
      {
          wchar_t dest[50] = L"";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          memmove(dest, data, wcslen(data)*sizeof(wchar_t));
          dest[50-1] = L'\0'; /* Ensure the destination buffer is null terminated */
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  