text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_61b.c
  Label Definition File: CWE761_Free_Pointer_Not_at_Start_of_Buffer.label.xml
  Template File: source-sinks-61b.tmpl.c
  */
  /*
   * @description
   * CWE: 761 Free Pointer not at Start of Buffer
   * BadSource: environment Read input from an environment variable
   * Sinks:
   *    GoodSink: free() memory correctly at the start of the buffer
   *    BadSink : free() memory not at the start of the buffer
   * Flow Variant: 61 Data flow: data returned 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
  
  #define SEARCH_CHAR 'S'
  
  #ifndef OMITBAD
  
  char * CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_61b_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, 100-dataLen-1);
          }
      }
      return data;
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodB2G() uses the BadSource with the GoodSink */
  char * CWE761_Free_Pointer_Not_at_Start_of_Buffer__char_environment_61b_goodB2GSource(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, 100-dataLen-1);
          }
      }
      return data;
  }
  
  #endif /* OMITGOOD */
  