text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__wchar_t_listen_socket_ofstream_67b.cpp
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-67b.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: 67 Data flow: data passed in a struct from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  #define BASEPATH L"c:\\temp\\"
  #else
  #include <wchar.h>
  #define BASEPATH L"/tmp/"
  #endif
  
  #ifdef _WIN32
  #include <winsock2.h>
  #include <windows.h>
  #include <direct.h>
  #pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */
  #define CLOSE_SOCKET closesocket
  #else
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <unistd.h>
  #define INVALID_SOCKET -1
  #define SOCKET_ERROR -1
  #define CLOSE_SOCKET close
  #define SOCKET int
  #endif
  
  #define TCP_PORT 27015
  #define LISTEN_BACKLOG 5
  
  #include <fstream>
  using namespace std;
  
  namespace CWE23_Relative_Path_Traversal__wchar_t_listen_socket_ofstream_67
  {
  
  typedef struct _structType
  {
      wchar_t * structFirst;
  } structType;
  
  #ifndef OMITBAD
  
  void badSink(structType myStruct)
  {
      wchar_t * data = myStruct.structFirst;
      {
          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(structType myStruct)
  {
      wchar_t * data = myStruct.structFirst;
      {
          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 */
  