text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__wchar_t_connect_socket_open_54e.c
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-54e.tmpl.c
  */
  /*
   * @description
   * CWE: 23 Relative Path Traversal
   * BadSource: connect_socket Read data using a connect socket (client side)
   * GoodSource: File name without a period or slash
   * Sink: open
   *    BadSink :
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  #define BASEPATH L"c:\\temp\\"
  #else
  #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
  # define PATH_SZ FILENAME_MAX
  #else /* NOT _WIN32 */
  # define INVALID_SOCKET -1
  # define SOCKET_ERROR -1
  # define CLOSE_SOCKET close
  # define SOCKET int
  # define PATH_SZ PATH_MAX
  #endif
  
  #define TCP_PORT 27015
  
  #ifdef _WIN32
  # define OPEN _wopen
  # define CLOSE _close
  #else
  # define OPEN wopen
  # define CLOSE close
  #endif
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE23_Relative_Path_Traversal__wchar_t_connect_socket_open_54e_bad_sink(wchar_t * data)
  {
      {
          int fd;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          fd = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
          if (fd != -1)
          {
              CLOSE(fd);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE23_Relative_Path_Traversal__wchar_t_connect_socket_open_54e_goodG2B_sink(wchar_t * data)
  {
      {
          int fd;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          fd = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
          if (fd != -1)
          {
              CLOSE(fd);
          }
      }
  }
  
  #endif /* OMITGOOD */
  