text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE122_Heap_Based_Buffer_Overflow__c_dest_char_memmove_53d.c
  Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_dest.string.label.xml
  Template File: sources-sink-53d.tmpl.c
  */
  /*
   * @description
   * CWE: 122 Heap Based Buffer Overflow
   * BadSource:  Allocate using malloc() and set data pointer to a small buffer
   * GoodSource: Allocate using malloc() and set data pointer to a large buffer
   * Sink: memmove
   *    BadSink : Copy string to data using memmove
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four functions are in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE122_Heap_Based_Buffer_Overflow__c_dest_char_memmove_53d_bad_sink(char * data)
  {
      {
          char src[100];
          memset(src, 'C', 100-1); /* fill with 'C's */
          src[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if src is larger than data */
          memmove(data, src, 100*sizeof(char));
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
          free(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE122_Heap_Based_Buffer_Overflow__c_dest_char_memmove_53d_goodG2B_sink(char * data)
  {
      {
          char src[100];
          memset(src, 'C', 100-1); /* fill with 'C's */
          src[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if src is larger than data */
          memmove(data, src, 100*sizeof(char));
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
          free(data);
      }
  }
  
  #endif /* OMITGOOD */
  