text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__char_file_vfprintf_63b.c
  Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
  Template File: sources-vasinks-63b.tmpl.c
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: file Read input from a file
   * GoodSource: Copy a fixed string into data
   * Sinks: vfprintf
   *    GoodSink: vfprintf with a format string
   *    BadSink : vfprintf without a format string
   * Flow Variant: 63 Data flow: pointer to data passed from one function to another in different source files
   *
   * */
  
  #include <stdarg.h>
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #ifdef _WIN32
  #define FILENAME "C:\\temp\\file.txt"
  #else
  #define FILENAME "/tmp/file.txt"
  #endif
  
  #ifndef OMITBAD
  
  static void badVaSink(char * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          vfprintf(stdout, data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_file_vfprintf_63b_badSink(char * * dataPtr)
  {
      char * data = *dataPtr;
      badVaSink(data, data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2BVaSink(char * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          vfprintf(stdout, data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_file_vfprintf_63b_goodG2BSink(char * * dataPtr)
  {
      char * data = *dataPtr;
      goodG2BVaSink(data, data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  static void goodB2GVaSink(char * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* FIX: Specify the format disallowing a format string vulnerability */
          vfprintf(stdout, "%s", args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_file_vfprintf_63b_goodB2GSink(char * * dataPtr)
  {
      char * data = *dataPtr;
      goodB2GVaSink(data, data);
  }
  
  #endif /* OMITGOOD */
  