text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE805_int_alloca_memmove_74b.cpp
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE805.label.xml
  Template File: sources-sink-74b.tmpl.cpp
  */
  /*
   * @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 int array to data using memmove
   * Flow Variant: 74 Data flow: data passed in a map from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <map>
  
  using namespace std;
  
  namespace CWE121_Stack_Based_Buffer_Overflow__CWE805_int_alloca_memmove_74
  {
  
  #ifndef OMITBAD
  
  void badSink(map<int, int *> dataMap)
  {
      /* copy data out of dataMap */
      int * data = dataMap[2];
      {
          int source[100] = {0}; /* fill with 0's */
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, source, 100*sizeof(int));
          printIntLine(data[0]);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, int *> dataMap)
  {
      int * data = dataMap[2];
      {
          int source[100] = {0}; /* fill with 0's */
          /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */
          memmove(data, source, 100*sizeof(int));
          printIntLine(data[0]);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  