text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE805_struct_alloca_memmove_53d.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE805.label.xml
  Template File: sources-sink-53d.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
   * Sink: memmove
   *    BadSink : Copy twoIntsStruct array to data using memmove
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_struct_alloca_memmove_53d_badSink(twoIntsStruct * data)
  {
      {
          twoIntsStruct source[100];
          {
              size_t i;
              /* Initialize array */
              for (i = 0; i < 100; i++)
              {
                  source[i].intOne = 0;
                  source[i].intTwo = 0;
              }
          }
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, source, 100*sizeof(twoIntsStruct));
          printStructLine(&data[0]);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_struct_alloca_memmove_53d_goodG2BSink(twoIntsStruct * data)
  {
      {
          twoIntsStruct source[100];
          {
              size_t i;
              /* Initialize array */
              for (i = 0; i < 100; i++)
              {
                  source[i].intOne = 0;
                  source[i].intTwo = 0;
              }
          }
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, source, 100*sizeof(twoIntsStruct));
          printStructLine(&data[0]);
      }
  }
  
  #endif /* OMITGOOD */
  