text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__char_listen_socket_ofstream_74b.cpp
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-74b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 23 Relative Path Traversal
   * BadSource: listen_socket Read data using a listen socket (server side)
   * GoodSource: Use a fixed file name
   * Sinks: ofstream
   *    BadSink : Open the file named in data using ofstream::open()
   * 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>
  
  #ifdef _WIN32
  #define BASEPATH "c:\\temp\\"
  #else
  #include <wchar.h>
  #define BASEPATH "/tmp/"
  #endif
  
  #include <fstream>
  using namespace std;
  
  using namespace std;
  
  namespace CWE23_Relative_Path_Traversal__char_listen_socket_ofstream_74
  {
  
  #ifndef OMITBAD
  
  void badSink(map<int, char *> dataMap)
  {
      /* copy data out of dataMap */
      char * data = dataMap[2];
      {
          ofstream outputFile;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          outputFile.open((char *)data);
          outputFile.close();
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(map<int, char *> dataMap)
  {
      char * data = dataMap[2];
      {
          ofstream outputFile;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          outputFile.open((char *)data);
          outputFile.close();
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  