text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE193_char_ncpy_61b.c
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE193.label.xml
  Template File: sources-sink-61b.tmpl.c
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * 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
   * Sinks: ncpy
   *    BadSink : Copy string to data using strncpy()
   * Flow Variant: 61 Data flow: data returned from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  /* MAINTENANCE NOTE: The length of this string should equal the 10 */
  #define SRC_STRING "AAAAAAAAAA"
  
  #ifndef OMITBAD
  
  char * CWE122_Heap_Based_Buffer_Overflow__c_CWE193_char_ncpy_61b_badSource(char * data)
  {
      /* FLAW: Did not leave space for a null terminator */
      data = (char *)malloc(10*sizeof(char));
      if (data == NULL) {exit(-1);}
      return data;
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B() uses the GoodSource with the BadSink */
  char * CWE122_Heap_Based_Buffer_Overflow__c_CWE193_char_ncpy_61b_goodG2BSource(char * data)
  {
      /* FIX: Allocate space for a null terminator */
      data = (char *)malloc((10+1)*sizeof(char));
      if (data == NULL) {exit(-1);}
      return data;
  }
  
  #endif /* OMITGOOD */
  