text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE36_Absolute_Path_Traversal__char_environment_fopen_62b.cpp
  Label Definition File: CWE36_Absolute_Path_Traversal.label.xml
  Template File: sources-sink-62b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 36 Absolute Path Traversal
   * BadSource: environment Read input from an environment variable
   * GoodSource: Full path and file name
   * Sinks: fopen
   *    BadSink : Open the file named in data using fopen()
   * Flow Variant: 62 Data flow: data flows using a C++ reference from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #define ENV_VARIABLE "ADD"
  
  #ifdef _WIN32
  #define GETENV getenv
  #else
  #define GETENV getenv
  #endif
  
  #ifdef _WIN32
  #define FOPEN fopen
  #else
  #define FOPEN fopen
  #endif
  
  namespace CWE36_Absolute_Path_Traversal__char_environment_fopen_62
  {
  
  #ifndef OMITBAD
  
  void badSource(char * &data)
  {
      {
          /* Append input from an environment variable to data */
          size_t dataLen = strlen(data);
          char * environment = GETENV(ENV_VARIABLE);
          /* If there is data in the environment variable */
          if (environment != NULL)
          {
              /* POTENTIAL FLAW: Read data from an environment variable */
              strncat(data+dataLen, environment, FILENAME_MAX-dataLen-1);
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B() uses the GoodSource with the BadSink */
  void goodG2BSource(char * &data)
  {
  #ifdef _WIN32
      /* FIX: Use a fixed, full path and file name */
      strcat(data, "c:\\temp\\file.txt");
  #else
      /* FIX: Use a fixed, full path and file name */
      strcat(data, "/tmp/file.txt");
  #endif
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  