text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE23_Relative_Path_Traversal__char_console_open_84_bad.cpp
  Label Definition File: CWE23_Relative_Path_Traversal.label.xml
  Template File: sources-sink-84_bad.tmpl.cpp
  */
  /*
   * @description
   * CWE: 23 Relative Path Traversal
   * BadSource: console Read input from the console
   * GoodSource: Use a fixed file name
   * Sinks: open
   *    BadSink : Open the file named in data using open()
   * Flow Variant: 84 Data flow: data passed to class constructor and destructor by declaring the class object on the heap and deleting it after use
   *
   * */
  #ifndef OMITBAD
  
  #include "std_testcase.h"
  #include "CWE23_Relative_Path_Traversal__char_console_open_84.h"
  
  #ifdef _WIN32
  #define OPEN _open
  #define CLOSE _close
  #else
  #include <unistd.h>
  #define OPEN open
  #define CLOSE close
  #endif
  
  namespace CWE23_Relative_Path_Traversal__char_console_open_84
  {
  CWE23_Relative_Path_Traversal__char_console_open_84_bad::CWE23_Relative_Path_Traversal__char_console_open_84_bad(char * dataCopy)
  {
      data = dataCopy;
      {
          /* Read input from the console */
          size_t dataLen = strlen(data);
          /* if there is room in data, read into it from the console */
          if (FILENAME_MAX-dataLen > 1)
          {
              /* POTENTIAL FLAW: Read data from the console */
              if (fgets(data+dataLen, (int)(FILENAME_MAX-dataLen), stdin) != NULL)
              {
                  /* The next few lines remove the carriage return from the string that is
                   * inserted by fgets() */
                  dataLen = strlen(data);
                  if (dataLen > 0 && data[dataLen-1] == '\n')
                  {
                      data[dataLen-1] = '\0';
                  }
              }
              else
              {
                  printLine("fgets() failed");
                  /* Restore NUL terminator if fgets fails */
                  data[dataLen] = '\0';
              }
          }
      }
  }
  
  CWE23_Relative_Path_Traversal__char_console_open_84_bad::~CWE23_Relative_Path_Traversal__char_console_open_84_bad()
  {
      {
          int fileDesc;
          /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
          fileDesc = OPEN(data, O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
          if (fileDesc != -1)
          {
              CLOSE(fileDesc);
          }
      }
  }
  }
  #endif /* OMITBAD */
  