text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__char_console_snprintf_66b.c
  Label Definition File: CWE134_Uncontrolled_Format_String.label.xml
  Template File: sources-sinks-66b.tmpl.c
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: console Read input from the console
   * GoodSource: Copy a fixed string into data
   * Sinks: snprintf
   *    GoodSink: snprintf with "%s" as the third argument and data as the fourth
   *    BadSink : snprintf with data as the third argument
   * Flow Variant: 66 Data flow: data passed in an array from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #ifdef _WIN32
  #define SNPRINTF _snprintf
  #else
  #define SNPRINTF snprintf
  #endif
  
  #ifndef OMITBAD
  
  void CWE134_Uncontrolled_Format_String__char_console_snprintf_66b_badSink(char * dataArray[])
  {
      /* copy data out of dataArray */
      char * data = dataArray[2];
      {
          char dest[100] = "";
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          SNPRINTF(dest, 100-1, data);
          printLine(dest);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE134_Uncontrolled_Format_String__char_console_snprintf_66b_goodG2BSink(char * dataArray[])
  {
      char * data = dataArray[2];
      {
          char dest[100] = "";
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          SNPRINTF(dest, 100-1, data);
          printLine(dest);
      }
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  void CWE134_Uncontrolled_Format_String__char_console_snprintf_66b_goodB2GSink(char * dataArray[])
  {
      char * data = dataArray[2];
      {
          char dest[100] = "";
          /* FIX: Specify the format disallowing a format string vulnerability */
          SNPRINTF(dest, 100-1, "%s", data);
          printLine(dest);
      }
  }
  
  #endif /* OMITGOOD */
  