text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE36_Absolute_Path_Traversal__char_listen_socket_open_65b.c
  Label Definition File: CWE36_Absolute_Path_Traversal.label.xml
  Template File: sources-sink-65b.tmpl.c
  */
  /*
   * @description
   * CWE: 36 Absolute Path Traversal
   * BadSource: listen_socket Read data using a listen socket (server side)
   * GoodSource: Full path and file name
   * Sinks: open
   *    BadSink :
   * Flow Variant: 65 Data/control flow: data passed as an argument from one function to a function in a different source file called via a function pointer
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  # include <winsock2.h>
  # include <windows.h>
  # include <direct.h>
  # define PATH_SZ FILENAME_MAX
  # pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */
  # define CLOSE_SOCKET closesocket
  #else
  # define PATH_SZ PATH_MAX
  # define INVALID_SOCKET -1
  # define SOCKET_ERROR -1
  # define CLOSE_SOCKET close
  # define SOCKET int
  #endif
  
  #define TCP_PORT 27015
  #define LISTEN_BACKLOG 5
  
  #ifdef _WIN32
  # define OPEN _open
  # define CLOSE _close
  #else
  # define OPEN open
  # define CLOSE close
  #endif
  
  #ifndef OMITBAD
  
  void CWE36_Absolute_Path_Traversal__char_listen_socket_open_65b_bad_sink(char * 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 CWE36_Absolute_Path_Traversal__char_listen_socket_open_65b_goodG2B_sink(char * 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 */
  