text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE126_Buffer_Overread__char_alloca_loop_64b.c
  Label Definition File: CWE126_Buffer_Overread.stack.label.xml
  Template File: sources-sink-64b.tmpl.c
  */
  /*
   * @description
   * CWE: 126 Buffer Over-read
   * BadSource:  Set data pointer to a small buffer
   * GoodSource: Set data pointer to a large buffer
   * Sinks: loop
   *    BadSink : Copy data to string using a loop
   * 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 CWE126_Buffer_Overread__char_alloca_loop_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);
      {
          size_t i, dest_sz;
          char dest[100];
          memset(dest, 'C', 100-1);
          dest[100-1] = '\0'; /* null terminate */
          dest_sz = strlen(dest);
          /* POTENTIAL FLAW: using length of the dest where data
           * could be smaller than dest causing buffer overread */
          for (i = 0; i < dest_sz; i++)
          {
              dest[i] = data[i];
          }
          dest[100-1] = '\0';
          printLine(dest);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE126_Buffer_Overread__char_alloca_loop_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);
      {
          size_t i, dest_sz;
          char dest[100];
          memset(dest, 'C', 100-1);
          dest[100-1] = '\0'; /* null terminate */
          dest_sz = strlen(dest);
          /* POTENTIAL FLAW: using length of the dest where data
           * could be smaller than dest causing buffer overread */
          for (i = 0; i < dest_sz; i++)
          {
              dest[i] = data[i];
          }
          dest[100-1] = '\0';
          printLine(dest);
      }
  }
  
  #endif /* OMITGOOD */
  