text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__dest_struct_alloca_memmove_66b.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__dest.label.xml
  Template File: sources-sink-66b.tmpl.c
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Set data pointer to the bad buffer
   * GoodSource: Set data pointer to the good buffer
   * Sinks: memmove
   *    BadSink : Copy twoints array to data using memmove
   * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__dest_struct_alloca_memmove_66b_bad_sink(twoints * data_array[])
  {
      /* copy data out of data_array */
      twoints * data = data_array[2];
      {
          twoints src[100];
          {
              size_t i;
              /* Initialize array */
              for (i = 0; i < 100; i++)
              {
                  src[i].a = 0;
                  src[i].b = 0;
              }
          }
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, src, 100*sizeof(twoints));
          printStructLine(&data[0]);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__dest_struct_alloca_memmove_66b_goodG2B_sink(twoints * data_array[])
  {
      twoints * data = data_array[2];
      {
          twoints src[100];
          {
              size_t i;
              /* Initialize array */
              for (i = 0; i < 100; i++)
              {
                  src[i].a = 0;
                  src[i].b = 0;
              }
          }
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, src, 100*sizeof(twoints));
          printStructLine(&data[0]);
      }
  }
  
  #endif /* OMITGOOD */
  