text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__src_char_alloca_snprintf_64b.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__src.string.label.xml
  Template File: sources-sink-64b.tmpl.c
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Initialize data as a large string
   * GoodSource: Initialize data as a small string
   * Sinks: snprintf
   *    BadSink : Copy data to string using snprintf
   * 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 CWE121_Stack_Based_Buffer_Overflow__src_char_alloca_snprintf_64b_bad_sink(void * void_data_ptr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * data_ptr = (char * *)void_data_ptr;
      /* dereference data_ptr into data */
      char * data = (*data_ptr);
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          _snprintf(dest, strlen(data), "%s", data);
          printLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__src_char_alloca_snprintf_64b_goodG2B_sink(void * void_data_ptr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * data_ptr = (char * *)void_data_ptr;
      /* dereference data_ptr into data */
      char * data = (*data_ptr);
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          _snprintf(dest, strlen(data), "%s", data);
          printLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  