centos 7
integer weakness #2


Weakness Breakdown


An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:



The highlighted line of code below is the trigger point of this particular Centos 7 integer weakness.


static void
_error_mapping_external_port (GUPnPSimpleIgd *igd, GError *error,
    gchar *proto, guint external_port,
    gchar *description, gpointer user_data)
  g_error ("proto:%s port:%u desc:%s error: %s:%d %s", proto, external_port,
      description, g_quark_to_string (error->domain), error->code, error->message);

main (int argc, char **argv)

  if (argc != 5)
    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
    return 0;

  external_port = atoi (argv[1]);
  internal_port = atoi (argv[3]);
  g_return_val_if_fail (external_port && internal_port, 1);

  g_type_init ();
  g_thread_init (NULL);

  ctx = g_main_context_new ();
  loop = g_main_loop_new (ctx, FALSE);

  g_main_context_push_thread_default (ctx);
  igd = gupnp_simple_igd_new ();

  g_signal_connect (igd, "mapped-external-port",
      G_CALLBACK (_mapped_external_port),
  g_signal_connect (igd, "error-mapping-port",
      G_CALLBACK (_error_mapping_external_port),

  gupnp_simple_igd_add_port (igd, "TCP", external_port, argv[2],
      internal_port, 20, argv[4]);

  g_main_loop_run (loop);

  g_object_unref (igd);
  g_main_loop_unref (loop); 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.