From 1f47715a589b81c62de8fd49a342bf4cf4be770a Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 1 Oct 2014 13:30:27 -0400 Subject: [PATCH] Fix: detect size_t overflow in syscall table init Fixes Coverity issue 1242317. Signed-off-by: David Goulet --- src/bin/lttng-sessiond/syscall.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c index ee7578051..b4f2e1eca 100644 --- a/src/bin/lttng-sessiond/syscall.c +++ b/src/bin/lttng-sessiond/syscall.c @@ -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); -- 2.34.1