text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68b.c
  Label Definition File: CWE124_Buffer_Underwrite.stack.label.xml
  Template File: sources-sink-68b.tmpl.c
  */
  /*
   * @description
   * CWE: 124 Buffer Underwrite
   * BadSource:  Set data pointer to before the allocated memory buffer
   * GoodSource: Set data pointer to the allocated memory buffer
   * Sink: ncpy
   *    BadSink : Copy string to data using wcsncpy
   * Flow Variant: 68 Data flow: data passed as a global variable from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  extern wchar_t * CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68_badData;
  extern wchar_t * CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68_goodG2BData;
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68b_badSink()
  {
      wchar_t * data = CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68_badData;
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with 'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcsncpy(data, source, 100-1);
          /* Ensure the destination buffer is null terminated */
          data[100-1] = L'\0';
          printWLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68b_goodG2BSink()
  {
      wchar_t * data = CWE124_Buffer_Underwrite__wchar_t_alloca_ncpy_68_goodG2BData;
      {
          wchar_t source[100];
          wmemset(source, L'C', 100-1); /* fill with 'C's */
          source[100-1] = L'\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copying data to memory before the destination buffer */
          wcsncpy(data, source, 100-1);
          /* Ensure the destination buffer is null terminated */
          data[100-1] = L'\0';
          printWLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  