text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cat_51b.c
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_dest.label.xml
  Template File: sources-sink-51b.tmpl.c
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Allocate using malloc() and set data pointer to a small buffer
   * GoodSource: Allocate using malloc() and set data pointer to a large buffer
   * Sink: cat
   *    BadSink : Copy string to data using wcscat
   * Flow Variant: 51 Data flow: data passed as an argument from one function to another 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 CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cat_51b_badSink(wchar_t * data)
  {
      {
          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 source is larger than sizeof(data)-strlen(data) */
          wcscat(data, source);
          printWLine(data);
          free(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE122_Heap_Based_Buffer_Overflow__c_dest_wchar_t_cat_51b_goodG2BSink(wchar_t * data)
  {
      {
          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 source is larger than sizeof(data)-strlen(data) */
          wcscat(data, source);
          printWLine(data);
          free(data);
      }
  }
  
  #endif /* OMITGOOD */
  