text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68b.c
  Label Definition File: CWE121_Stack_Based_Buffer_Overflow__CWE805.string.label.xml
  Template File: sources-sink-68b.tmpl.c
  */
  /*
   * @description
   * CWE: 121 Stack Based Buffer Overflow
   * BadSource:  Set data pointer to the bad buffer
   * GoodSource: Set data pointer to the good buffer
   * Sink: ncpy
   *    BadSink : Copy string to data using strncpy
   * Flow Variant: 68 Data flow: data passed as a global variable from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  extern char * CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68_badData;
  extern char * CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68_goodG2BData;
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68b_badSink()
  {
      char * data = CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68_badData;
      {
          char source[100];
          memset(source, 'C', 100-1); /* fill with 'C's */
          source[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          strncpy(data, source, 100-1);
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68b_goodG2BSink()
  {
      char * data = CWE121_Stack_Based_Buffer_Overflow__CWE805_char_alloca_ncpy_68_goodG2BData;
      {
          char source[100];
          memset(source, 'C', 100-1); /* fill with 'C's */
          source[100-1] = '\0'; /* null terminate */
          /* POTENTIAL FLAW: Possible buffer overflow if the size of data is less than the length of source */
          strncpy(data, source, 100-1);
          data[100-1] = '\0'; /* Ensure the destination buffer is null terminated */
          printLine(data);
      }
  }
  
  #endif /* OMITGOOD */
  