text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__wchar_t_environment_vprintf_52c.c
  Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
  Template File: sources-vasinks-52c.tmpl.c
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: environment Read input from an environment variable
   * GoodSource: Copy a fixed string into data
   * Sinks: vprintf
   *    GoodSink: vwprintf with a format string
   *    BadSink : vwprintf without a format string
   * Flow Variant: 52 Data flow: data passed as an argument from one function to another to another in three different source files
   *
   * */
  
  #include <stdarg.h>
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #define ENV_VARIABLE L"ADD"
  
  #ifdef _WIN32
  #define GETENV _wgetenv
  #else
  #define GETENV getenv
  #endif
  
  #ifndef OMITBAD
  
  static void badVaSink(wchar_t * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          vwprintf(data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__wchar_t_environment_vprintf_52c_badSink(wchar_t * data)
  {
      badVaSink(data, data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2BVaSink(wchar_t * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* POTENTIAL FLAW: Do not specify the format allowing a possible format string vulnerability */
          vwprintf(data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__wchar_t_environment_vprintf_52c_goodG2BSink(wchar_t * data)
  {
      goodG2BVaSink(data, data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  static void goodB2GVaSink(wchar_t * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* FIX: Specify the format disallowing a format string vulnerability */
          vwprintf(L"%s", args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__wchar_t_environment_vprintf_52c_goodB2GSink(wchar_t * data)
  {
      goodB2GVaSink(data, data);
  }
  
  #endif /* OMITGOOD */
  