text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_64b.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806.label.xml
  Template File: sources-sink-64b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Initialize data as a large string
   * GoodSource: Initialize data as a small string
   * Sinks: ncat
   *    BadSink : Copy data to string using strncat
   * Flow Variant: 64 Data flow: void pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_ncat_64
  {
  
  #ifndef OMITBAD
  
  void badSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * dataPtr = (char * *)dataVoidPtr;
      /* dereference dataPtr into data */
      char * data = (*dataPtr);
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than sizeof(dest)-strlen(dest)*/
          strncat(dest, data, strlen(data));
          dest[50-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * dataPtr = (char * *)dataVoidPtr;
      /* dereference dataPtr into data */
      char * data = (*dataPtr);
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than sizeof(dest)-strlen(dest)*/
          strncat(dest, data, strlen(data));
          dest[50-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  