text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE36_Absolute_Path_Traversal__char_connect_socket_ofstream_52c.cpp
  Label Definition File: CWE36_Absolute_Path_Traversal.label.xml
  Template File: sources-sink-52c.tmpl.cpp
  */
  /*
   * @description
   * CWE: 36 Absolute Path Traversal
   * BadSource: connect_socket Read data using a connect socket (client side)
   * GoodSource: Full path and file name
   * Sink: ofstream
   *    BadSink : Open the file named in data using ofstream::open()
   * Flow Variant: 52 Data flow: data passed as an argument from one function to another to another in three different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #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 /* NOT _WIN32 */
  #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 IP_ADDRESS "127.0.0.1"
  
  #include <fstream>
  using namespace std;
  
  namespace CWE36_Absolute_Path_Traversal__char_connect_socket_ofstream_52
  {
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void badSink_c(char * data)
  {
      {
          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_c(char * data)
  {
      {
          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 */
  