text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67b.c
  Label Definition File: CWE195_Signed_To_Unsigned_Conversion.label.xml
  Template File: sources-sink-67b.tmpl.c
  */
  /*
   * @description
   * CWE: 195 Signed to Unsigned Conversion
   * BadSource: listen_socket Read data using a listen socket (server side)
   * GoodSource: Positive integer
   * Sinks: memmove
   *    BadSink : Copy strings using memmove() with the length of data
   * Flow Variant: 67 Data flow: data passed in a struct from one function to another in different source files
   *
   * */
  
  #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
  #else
  # define INVALID_SOCKET -1
  # define SOCKET_ERROR -1
  # define CLOSE_SOCKET close
  # define SOCKET int
  #endif
  
  #define TCP_PORT 27015
  #define LISTEN_BACKLOG 5
  #define CHAR_ARRAY_SIZE sizeof(data)*sizeof(data)
  
  typedef struct _CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67_struct_type
  {
      int a;
  } CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67_struct_type;
  
  #ifndef OMITBAD
  
  void CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67b_bad_sink(CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67_struct_type my_struct)
  {
      int data = my_struct.a;
      {
          char src[100];
          char dest[100] = "";
          memset(src, 'A', 100-1);
          src[100-1] = '\0';
          if (data < 100)
          {
              /* POTENTIAL FLAW: data is interpreted as an unsigned int - if its value is negative,
               * the sign conversion could result in a very large number */
              memmove(dest, src, data);
              dest[data] = '\0'; /* NULL terminate */
          }
          printLine(dest);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67b_goodG2B_sink(CWE195_Signed_To_Unsigned_Conversion__listen_socket_memmove_67_struct_type my_struct)
  {
      int data = my_struct.a;
      {
          char src[100];
          char dest[100] = "";
          memset(src, 'A', 100-1);
          src[100-1] = '\0';
          if (data < 100)
          {
              /* POTENTIAL FLAW: data is interpreted as an unsigned int - if its value is negative,
               * the sign conversion could result in a very large number */
              memmove(dest, src, data);
              dest[data] = '\0'; /* NULL terminate */
          }
          printLine(dest);
      }
  }
  
  #endif /* OMITGOOD */
  