text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__char_connect_socket_vfprintf_53d.c
  Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
  Template File: sources-vasinks-53d.tmpl.c
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: connect_socket Read data using a connect socket (client side)
   * GoodSource: Copy a fixed string into data
   * Sinks: vfprintf
   *    GoodSink: vfprintf with a format string
   *    BadSink : vfprintf without a format string
   * Flow Variant: 53 Data flow: data passed as an argument from one function through two others to a fourth; all four functions are in different source files
   *
   * */
  
  #include <stdarg.h>
  #include "std_testcase.h"
  
  #ifdef _WIN32
  # include <winsock2.h>
  # include <windows.h>
  # include <direct.h>
  # pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */
  # define CLOSE_SOCKET closesocket
  # define PATH_SZ 100
  #else /* NOT _WIN32 */
  # define INVALID_SOCKET -1
  # define SOCKET_ERROR -1
  # define CLOSE_SOCKET close
  # define SOCKET int
  # define PATH_SZ PATH_MAX
  #endif
  
  #define TCP_PORT 27015
  
  #ifndef OMITBAD
  
  static void bad_vasink(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_connect_socket_vfprintf_53d_bad_sink(char * data)
  {
      bad_vasink(data, data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2B_vasink(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_connect_socket_vfprintf_53d_goodG2B_sink(char * data)
  {
      goodG2B_vasink(data, data);
  }
  
  /* goodB2G uses the BadSource with the GoodSink */
  static void goodB2G_vasink(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_connect_socket_vfprintf_53d_goodB2G_sink(char * data)
  {
      goodB2G_vasink(data, data);
  }
  
  #endif /* OMITGOOD */
  