text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84_bad.cpp
  Label Definition File: CWE78_OS_Command_Injection.strings.label.xml
  Template File: sources-sink-84_bad.tmpl.cpp
  */
  /*
   * @description
   * CWE: 78 OS Command Injection
   * BadSource: environment Read input from an environment variable
   * GoodSource: Fixed string
   * Sinks: w32_spawnvp
   *    BadSink : execute command with spawnvp
   * 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 "CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84.h"
  
  #define ENV_VARIABLE "ADD"
  
  #ifdef _WIN32
  #define GETENV getenv
  #else
  #define GETENV getenv
  #endif
  
  #include <process.h>
  
  namespace CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84
  {
  CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84_bad::CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84_bad(char * dataCopy)
  {
      data = dataCopy;
      {
          /* 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, 100-dataLen-1);
          }
      }
  }
  
  CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84_bad::~CWE78_OS_Command_Injection__char_environment_w32_spawnvp_84_bad()
  {
      {
          char *args[] = {COMMAND_INT_PATH, COMMAND_ARG1, COMMAND_ARG3, NULL};
          /* spawnvp - searches for the location of the command among
           * the directories specified by the PATH environment variable */
          /* POTENTIAL FLAW: Execute command without validating input possibly leading to command injection */
          _spawnvp(_P_WAIT, COMMAND_INT, args);
      }
  }
  }
  #endif /* OMITBAD */
  