rhel 7
integer weakness #20


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 Red Hat Enterprise Linux 7 integer weakness.

 #include <stdlib.h>
#include <gst/gst.h>
#include "gst/glib-compat-private.h"

#define BUFFER_SIZE (1400)

main (gint argc, gchar * argv[])
  gint i;
  GstBuffer *tmp;
  GstBufferPool *pool;
  GstClockTime start, end;
  GstClockTimeDiff dur1, dur2;
  guint64 nbuffers;
  GstStructure *conf;

  gst_init (&argc, &argv);

  if (argc != 2) {
    g_print ("usage: %s <nbuffers>\n", argv[0]);
    exit (-1);

  nbuffers = atoi (argv[1]);

  if (nbuffers <= 0) {
    g_print ("number of buffers must be greater than 0\n");
    exit (-3);

  /* Let's just make sure the GstBufferClass is loaded ... */
  tmp = gst_buffer_new ();
  gst_buffer_unref (tmp);

  pool = gst_buffer_pool_new ();

  conf = gst_buffer_pool_get_config (pool);
  gst_buffer_pool_config_set_params (conf, NULL, BUFFER_SIZE, 0, 0);
  gst_buffer_pool_set_config (pool, conf);

  gst_buffer_pool_set_active (pool, TRUE);

  /* allocate buffers directly */
  start = gst_util_get_timestamp ();
  for (i = 0; i < nbuffers; i++) {
    tmp = gst_buffer_new_allocate (NULL, BUFFER_SIZE, NULL);
    gst_buffer_unref (tmp);
  end = gst_util_get_timestamp (); 

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.