text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE127_Buffer_Underread__malloc_char_cpy_64b.c
  Label Definition File: CWE127_Buffer_Underread__malloc.label.xml
  Template File: sources-sink-64b.tmpl.c
  */
  /*
   * @description
   * CWE: 127 Buffer Under-read
   * BadSource:  Set data pointer to before the allocated memory buffer
   * GoodSource: Set data pointer to the allocated memory buffer
   * Sinks: cpy
   *    BadSink : Copy data to string using strcpy
   * 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>
  
  #ifndef OMITBAD
  
  void CWE127_Buffer_Underread__malloc_char_cpy_64b_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[100*2];
          memset(dest, 'C', 100*2-1); /* fill with 'C's */
          dest[100*2-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copy from a memory location located before the source buffer */
          strcpy(dest, data);
          printLine(dest);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
           * returned by malloc() so can't safely call free() on it */
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE127_Buffer_Underread__malloc_char_cpy_64b_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[100*2];
          memset(dest, 'C', 100*2-1); /* fill with 'C's */
          dest[100*2-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possibly copy from a memory location located before the source buffer */
          strcpy(dest, data);
          printLine(dest);
          /* INCIDENTAL CWE-401: Memory Leak - data may not point to location
           * returned by malloc() so can't safely call free() on it */
      }
  }
  
  #endif /* OMITGOOD */
  