text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE124_Buffer_Underwrite__malloc_char_memmove_62b.cpp
  Label Definition File: CWE124_Buffer_Underwrite__malloc.label.xml
  Template File: sources-sink-62b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 124 Buffer Underwrite
   * BadSource:  Set data pointer to before the allocated memory buffer
   * GoodSource: Set data pointer to the allocated memory buffer
   * Sinks: memmove
   *    BadSink : Copy string to data using memmove
   * Flow Variant: 62 Data flow: data flows using a C++ reference from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  namespace CWE124_Buffer_Underwrite__malloc_char_memmove_62
  {
  
  #ifndef OMITBAD
  
  void badSource(char * &data)
  {
      {
          char * dataBuffer = (char *)malloc(100*sizeof(char));
          memset(dataBuffer, 'A', 100-1);
          dataBuffer[100-1] = '\0';
          /* FLAW: Set data pointer to before the allocated memory buffer */
          data = dataBuffer - 8;
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B() uses the GoodSource with the BadSink */
  void goodG2BSource(char * &data)
  {
      {
          char * dataBuffer = (char *)malloc(100*sizeof(char));
          memset(dataBuffer, 'A', 100-1);
          dataBuffer[100-1] = '\0';
          /* FIX: Set data pointer to the allocated memory buffer */
          data = dataBuffer;
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  