text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE131_Incorrect_Calculation_Of_Buffer_Size__wchar_t_memcpy_53d.c
  Label Definition File: CWE131_Incorrect_Calculation_Of_Buffer_Size.off_by_one.label.xml
  Template File: sources-sink-53d.tmpl.c
  */
  /*
   * @description
   * CWE: 131 Incorrect Calculation of Buffer Size
   * BadSource:  Allocate memory for a string, but do not allocate space for NULL terminator
   * GoodSource: Allocate enough memory for a string and the NULL terminator
   * Sink: memcpy
   *    BadSink : Copy string to data using memcpy()
   * 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"
  
  /* MAINTENANCE NOTE: The length of this string should equal the 10 */
  #define SRC_STRING L"AAAAAAAAAA"
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE131_Incorrect_Calculation_Of_Buffer_Size__wchar_t_memcpy_53d_bad_sink(wchar_t * data)
  {
      {
          wchar_t data_src[10+1] = SRC_STRING;
          /* POTENTIAL FLAW: data may not have enough space to hold data_src */
          memcpy(data, data_src, wcslen(data_src)*sizeof(wchar_t));
          data[wcslen(data_src)] = L'\0'; /* NULL terminate */
          printWLine(data);
          free(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE131_Incorrect_Calculation_Of_Buffer_Size__wchar_t_memcpy_53d_goodG2B_sink(wchar_t * data)
  {
      {
          wchar_t data_src[10+1] = SRC_STRING;
          /* POTENTIAL FLAW: data may not have enough space to hold data_src */
          memcpy(data, data_src, wcslen(data_src)*sizeof(wchar_t));
          data[wcslen(data_src)] = L'\0'; /* NULL terminate */
          printWLine(data);
          free(data);
      }
  }
  
  #endif /* OMITGOOD */
  