Fix: detect size_t overflow in syscall table init
authorDavid Goulet <dgoulet@efficios.com>
Wed, 1 Oct 2014 17:30:27 +0000 (13:30 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 1 Oct 2014 17:30:31 +0000 (13:30 -0400)
Fixes Coverity issue 1242317.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/syscall.c

index ee7578051e2a12d3322cb6e3d9fd4ae2946da1a7..b4f2e1eca92f2fb726aa774f8bc94f384bc2f000 100644 (file)
@@ -35,7 +35,7 @@ static size_t syscall_table_nb_entry;
  * Populate the system call table using the kernel tracer.
  *
  * Return 0 on success and the syscall table is allocated. On error, a negative
- * value is returned and the syscall table is set to NULL.
+ * value is returned.
  */
 int syscall_init_table(void)
 {
@@ -82,6 +82,14 @@ int syscall_init_table(void)
 
                        /* Double memory size. */
                        new_nbmem = max(index, nbmem << 1);
+                       if (new_nbmem < nbmem) {
+                               /* Overflow, stop everything, something went really wrong. */
+                               ERR("Syscall listing memory size overflow. Stopping");
+                               free(syscall_table);
+                               syscall_table = NULL;
+                               ret = -EINVAL;
+                               goto error;
+                       }
 
                        DBG("Reallocating syscall table from %zu to %zu entries", nbmem,
                                        new_nbmem);
This page took 0.026676 seconds and 4 git commands to generate.