text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61a.c
  Label Definition File: CWE36_Absolute_Path_Traversal.label.xml
  Template File: sources-sink-61a.tmpl.c
  */
  /*
   * @description
   * CWE: 36 Absolute Path Traversal
   * BadSource: fromConsole Read input from the console
   * GoodSource: Full path and file name
   * Sinks: open
   *    BadSink :
   * Flow Variant: 61 Data flow: data returned from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifdef _WIN32
  # define OPEN _wopen
  # define CLOSE _close
  #else
  # define OPEN wopen
  # define CLOSE close
  #endif
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  wchar_t * CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61b_bad_source(wchar_t * data);
  
  void CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61_bad()
  {
      wchar_t * data;
      wchar_t data_buf[FILENAME_MAX] = L"";
      data = data_buf;
      data = CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61b_bad_source(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 */
  wchar_t * CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61b_goodG2B_source(wchar_t * data);
  
  static void goodG2B()
  {
      wchar_t * data;
      wchar_t data_buf[FILENAME_MAX] = L"";
      data = data_buf;
      data = CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61b_goodG2B_source(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);
          }
      }
  }
  
  void CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61_good()
  {
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  /* Below is the main(). It is only used when building this testcase on
     its own for testing or for building a binary to use in testing binary
     analysis tools. It is not used when compiling all the testcases as one
     application, which is how source code analysis tools are tested. */
  
  #ifdef INCLUDEMAIN
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE36_Absolute_Path_Traversal__wchar_t_fromConsole_open_61_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  