Fix: syscall_table_nb_entry invalid value when no syscalls TPs are defined
v3: change commit message to include information regarding off-by-one
problems induced by 'index' and the use of 'index' as value of
syscall_table_nb_entry.
--
fscanf on an empty file returns directly without assigning value to
'index' leading to assigning the value of an uninitialized variable to
syscall_table_nb_entry. This can result in memory allocation problems
when listing syscalls on 'lttng list --kernel --syscall'[1][2].
Fixes at the same time an off-by-one problem for the
syscall_table_nb_entry value and an off-by-one error on table memory
reallocation.
The index value returned by fscanf is an index starting at 0. It is
later assigned to syscall_table_nb_entry which is used for memory
allocation and iteration during syscall_table_list. Forgetting to add 1
results in losing the last syscall during listing.
The parsed index value is also used to count how many elements should be
allocated during table reallocation, without any extra increment which
result in an off-by-one error. Hence, make sure to increment its value by
one when assigning the value of syscall_table_nb_entry. It does not
cause issues in practice because SYSCALL_TABLE_INIT_SIZE is nonzero, and
because we don't require the table to expand by more than the double of
its size at once (which could happen if we could have a hole in the
syscall table for instance).
Fixes #1091
[1] https://bugs.lttng.org/issues/1091
[2] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/
1671063/
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>