text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE114_Process_Control__w32_char_environment_64b.c
  Label Definition File: CWE114_Process_Control__w32.label.xml
  Template File: sources-sink-64b.tmpl.c
  */
  /*
   * @description
   * CWE: 114 Process Control
   * BadSource: environment Read input from an environment variable
   * GoodSource: Hard code the full pathname to the library
   * Sinks:
   *    BadSink : Load a dynamic link library
   * Flow Variant: 64 Data flow: void pointer to data passed from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  #define ENV_VARIABLE "ADD"
  
  #ifdef _WIN32
  #define GETENV getenv
  #else
  #define GETENV getenv
  #endif
  
  #include <windows.h>
  
  #ifndef OMITBAD
  
  void CWE114_Process_Control__w32_char_environment_64b_badSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * dataPtr = (char * *)dataVoidPtr;
      /* dereference dataPtr into data */
      char * data = (*dataPtr);
      {
          HMODULE hModule;
          /* POTENTIAL FLAW: If the path to the library is not specified, an attacker may be able to
           * replace his own file with the intended library */
          hModule = LoadLibraryA(data);
          if (hModule != NULL)
          {
              FreeLibrary(hModule);
              printLine("Library loaded and freed successfully");
          }
          else
          {
              printLine("Unable to load library");
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE114_Process_Control__w32_char_environment_64b_goodG2BSink(void * dataVoidPtr)
  {
      /* cast void pointer to a pointer of the appropriate type */
      char * * dataPtr = (char * *)dataVoidPtr;
      /* dereference dataPtr into data */
      char * data = (*dataPtr);
      {
          HMODULE hModule;
          /* POTENTIAL FLAW: If the path to the library is not specified, an attacker may be able to
           * replace his own file with the intended library */
          hModule = LoadLibraryA(data);
          if (hModule != NULL)
          {
              FreeLibrary(hModule);
              printLine("Library loaded and freed successfully");
          }
          else
          {
              printLine("Unable to load library");
          }
      }
  }
  
  #endif /* OMITGOOD */
  