text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67b.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__dest.string.label.xml
  Template File: sources-sink-67b.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: snprintf
   *    BadSink : Copy string to data using snwprintf
   * Flow Variant: 67 Data flow: data passed in a struct from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  typedef struct _CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67_struct_type
  {
      wchar_t * a;
  } CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67_struct_type;
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67b_bad_sink(CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67_struct_type my_struct)
  {
      wchar_t * data = my_struct.a;
      {
          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 size of data is less than the length of src */
          _snwprintf(data, 100, L"%s", src);
          printWLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67b_goodG2B_sink(CWE121_Stack_Based_Buffer_Overflow__dest_wchar_t_alloca_snprintf_67_struct_type my_struct)
  {
      wchar_t * data = my_struct.a;
      {
          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 size of data is less than the length of src */
          _snwprintf(data, 100, L"%s", src);
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  