text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84_goodB2G.cpp
  Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
  Template File: sources-vasinks-84_goodB2G.tmpl.cpp
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: console Read input from the console
   * GoodSource: Copy a fixed string into data
   * Sinks: vfprintf
   *    GoodSink: vfwprintf with a format string
   *    BadSink : vfwprintf without a format string
   * Flow Variant: 84 Data flow: data passed to class constructor and destructor by declaring the class object on the heap and deleting it after use
   *
   * */
  #ifndef OMITGOOD
  
  #include <stdarg.h>
  #include "std_testcase.h"
  #include "CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84.h"
  
  namespace CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84
  {
  CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84_goodB2G::CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84_goodB2G(wchar_t * dataCopy)
  {
      data = dataCopy;
      {
          /* Read input from the console */
          size_t dataLen = wcslen(data);
          /* if there is room in data, read into it from the console */
          if (100-dataLen > 1)
          {
              /* POTENTIAL FLAW: Read data from the console */
              if (fgetws(data+dataLen, (int)(100-dataLen), stdin) != NULL)
              {
                  /* The next few lines remove the carriage return from the string that is
                   * inserted by fgetws() */
                  dataLen = wcslen(data);
                  if (dataLen > 0 && data[dataLen-1] == L'\n')
                  {
                      data[dataLen-1] = L'\0';
                  }
              }
              else
              {
                  printLine("fgetws() failed");
                  /* Restore NUL terminator if fgetws fails */
                  data[dataLen] = L'\0';
              }
          }
      }
  }
  
  static void goodB2GVaSink(wchar_t * data, ...)
  {
      {
          va_list args;
          va_start(args, data);
          /* FIX: Specify the format disallowing a format string vulnerability */
          vfwprintf(stdout, L"%s", args);
          va_end(args);
      }
  }
  
  CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84_goodB2G::~CWE134_Uncontrolled_Format_String__wchar_t_console_vfprintf_84_goodB2G()
  {
      goodB2GVaSink(data, data);
  }
  }
  #endif /* OMITGOOD */
  