text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__wchar_t_console_w32CreateFile_52c.cpp
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-52c.tmpl.cpp
  */
  /*
   * @description
   * CWE: 23 Relative Path Traversal
   * BadSource: console Read input from the console
   * GoodSource: Use a fixed file name
   * Sink: w32CreateFile
   *    BadSink : Open the file named in data using CreateFile()
   * 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"
  
  #ifdef _WIN32
  #define BASEPATH L"c:\\temp\\"
  #else
  #include <wchar.h>
  #define BASEPATH L"/tmp/"
  #endif
  
  #include <windows.h>
  
  namespace CWE23_Relative_Path_Traversal__wchar_t_console_w32CreateFile_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(wchar_t * data)
  {
      {
          HANDLE hFile;
          /* POTENTIAL FLAW: Possibly creating and opening a file without validating the file name or path */
          hFile = CreateFileW(data,
                              (GENERIC_WRITE|GENERIC_READ),
                              0,
                              NULL,
                              OPEN_ALWAYS,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (hFile != INVALID_HANDLE_VALUE)
          {
              CloseHandle(hFile);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void goodG2BSink_c(wchar_t * data)
  {
      {
          HANDLE hFile;
          /* POTENTIAL FLAW: Possibly creating and opening a file without validating the file name or path */
          hFile = CreateFileW(data,
                              (GENERIC_WRITE|GENERIC_READ),
                              0,
                              NULL,
                              OPEN_ALWAYS,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (hFile != INVALID_HANDLE_VALUE)
          {
              CloseHandle(hFile);
          }
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  