text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_74b.cpp
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE805.string.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: ncpy
   *    BadSink : Copy string to data using strncpy
   * 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>
  
  using namespace std;
  
  namespace CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_74
  {
  
  #ifndef OMITBAD
  
  void badSink(map<int, char *> dataMap)
  {
      /* copy data out of dataMap */
      char * data = dataMap[2];
      {
          char source[100];
          memset(source, 'C', 100-1); /* fill with 'C's */
          source[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          strncpy(data, source, 100-1);
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, char *> dataMap)
  {
      char * data = dataMap[2];
      {
          char source[100];
          memset(source, 'C', 100-1); /* fill with 'C's */
          source[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          strncpy(data, source, 100-1);
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  