*/
#define _LGPL_SOURCE
+#include <stdbool.h>
+
#include <common/bitfield.h>
#include <common/common.h>
#include <common/kernel-ctl/kernel-ctl.h>
size_t nbmem;
FILE *fp;
/* Syscall data from the kernel. */
- size_t index;
+ size_t index = 0;
+ bool at_least_one_syscall = false;
uint32_t bitness;
char name[SYSCALL_NAME_LEN];
fd = kernctl_syscall_list(kernel_tracer_fd);
if (fd < 0) {
- ret = -errno;
+ ret = fd;
PERROR("kernelctl syscall list");
goto error_ioctl;
}
name = %" XSTR(SYSCALL_NAME_LEN) "[^;]; \
bitness = %u; };\n",
&index, name, &bitness) == 3) {
- if (index >= nbmem ) {
+ at_least_one_syscall = true;
+ if (index >= nbmem) {
struct syscall *new_list;
size_t new_nbmem;
/* Double memory size. */
- new_nbmem = max(index, nbmem << 1);
- if (new_nbmem < nbmem) {
+ new_nbmem = max(index + 1, nbmem << 1);
+ if (new_nbmem > (SIZE_MAX / sizeof(*new_list))) {
/* Overflow, stop everything, something went really wrong. */
ERR("Syscall listing memory size overflow. Stopping");
free(syscall_table);
}
syscall_table[index].index = index;
syscall_table[index].bitness = bitness;
- strncpy(syscall_table[index].name, name,
- sizeof(syscall_table[index].name));
+ if (lttng_strncpy(syscall_table[index].name, name,
+ sizeof(syscall_table[index].name))) {
+ ret = -EINVAL;
+ free(syscall_table);
+ syscall_table = NULL;
+ goto error;
+ }
/*
DBG("Syscall name '%s' at index %" PRIu32 " of bitness %u",
syscall_table[index].name,
*/
}
- syscall_table_nb_entry = index;
+ /* Index starts at 0. */
+ if (at_least_one_syscall) {
+ syscall_table_nb_entry = index + 1;
+ }
ret = 0;