text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__wchar_t_console_fopen_72b.cpp
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-72b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 23 Relative Path Traversal
   * BadSource: console Read input from the console
   * GoodSource: Use a fixed file name
   * Sinks: fopen
   *    BadSink : Open the file named in data using fopen()
   * Flow Variant: 72 Data flow: data passed in a vector from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <vector>
  
  #ifdef _WIN32
  #define BASEPATH L"c:\\temp\\"
  #else
  #include <wchar.h>
  #define BASEPATH L"/tmp/"
  #endif
  
  #ifdef _WIN32
  #define FOPEN _wfopen
  #else
  #define FOPEN fopen
  #endif
  
  using namespace std;
  
  namespace CWE23_Relative_Path_Traversal__wchar_t_console_fopen_72
  {
  
  #ifndef OMITBAD
  
  void badSink(vector<wchar_t *> dataVector)
  {
      /* copy data out of dataVector */
      wchar_t * data = dataVector[2];
      {
          FILE *pFile = NULL;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          pFile = FOPEN(data, L"wb+");
          if (pFile != NULL)
          {
              fclose(pFile);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink(vector<wchar_t *> dataVector)
  {
      wchar_t * data = dataVector[2];
      {
          FILE *pFile = NULL;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          pFile = FOPEN(data, L"wb+");
          if (pFile != NULL)
          {
              fclose(pFile);
          }
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  