text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE134_Uncontrolled_Format_String__char_listen_socket_vprintf_54e.c
  Label Definition File: CWE134_Uncontrolled_Format_String.vasinks.label.xml
  Template File: sources-vasinks-54e.tmpl.c
  */
  /*
   * @description
   * CWE: 134 Uncontrolled Format String
   * BadSource: listen_socket Read data using a listen socket (server side)
   * GoodSource: Copy a fixed string into data
   * Sinks: vprintf
   *    GoodSink: vprintf with a format string
   *    BadSink : vprintf without a format string
   * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
   *
   * */
  
  #include <stdarg.h>
  #include "std_testcase.h"
  
  #ifndef _WIN32
  #include <wchar.h>
  #endif
  
  #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
  #else
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <unistd.h>
  #define INVALID_SOCKET -1
  #define SOCKET_ERROR -1
  #define CLOSE_SOCKET close
  #define SOCKET int
  #endif
  
  #define TCP_PORT 27015
  #define LISTEN_BACKLOG 5
  
  #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 */
          vprintf(data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_listen_socket_vprintf_54e_badSink(char * data)
  {
      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 */
          vprintf(data, args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_listen_socket_vprintf_54e_goodG2BSink(char * data)
  {
      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 */
          vprintf("%s", args);
          va_end(args);
      }
  }
  
  void CWE134_Uncontrolled_Format_String__char_listen_socket_vprintf_54e_goodB2GSink(char * data)
  {
      goodB2GVaSink(data, data);
  }
  
  #endif /* OMITGOOD */
  