text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_snprintf_74b.cpp
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806.label.xml
  Template File: sources-sink-74b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 122 Heap 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: 74 Data flow: data passed in a map from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <map>
  
  #include <wchar.h>
  
  #ifdef _WIN32
  #define SNPRINTF _snprintf
  #else
  #define SNPRINTF snprintf
  #endif
  
  using namespace std;
  
  namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE806_char_snprintf_74
  {
  
  #ifndef OMITBAD
  
  void badSink(map<int, char *> dataMap)
  {
      /* copy data out of dataMap */
      char * data = dataMap[2];
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          SNPRINTF(dest, strlen(data), "%s", data);
          printLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, char *> dataMap)
  {
      char * data = dataMap[2];
      {
          char dest[50] = "";
          /* POTENTIAL FLAW: Possible buffer overflow if data is larger than dest */
          SNPRINTF(dest, strlen(data), "%s", data);
          printLine(data);
          delete [] data;
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  