text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_cat_53d.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__dest.string.label.xml
  Template File: sources-sink-53d.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
   * Sink: cat
   *    BadSink : Copy string to data using wcscat
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four 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__dest_wchar_t_alloca_cat_53d_bad_sink(wchar_t * data)
  {
      {
          wchar_t src[100];
          wmemset(src, L'C', 100-1); /* fill with L'C's */
          src[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the sizeof(data)-strlen(data) is less than the length of src */
          wcscat(data, src);
          printWLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_cat_53d_goodG2B_sink(wchar_t * data)
  {
      {
          wchar_t src[100];
          wmemset(src, L'C', 100-1); /* fill with L'C's */
          src[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the sizeof(data)-strlen(data) is less than the length of src */
          wcscat(data, src);
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  