X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsyscall.c;h=7d0a92b6b1376ced33f150fa677cf25b4c0d9315;hb=fc58be13f62e691645dd75d56ce26d2e121b13e0;hp=a994da52bbda8460b9e138e0426827e98531a629;hpb=39e3c47a70c252835593bf39d6f206cfb38aec80;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c index a994da52b..7d0a92b6b 100644 --- a/src/bin/lttng-sessiond/syscall.c +++ b/src/bin/lttng-sessiond/syscall.c @@ -16,6 +16,8 @@ */ #define _LGPL_SOURCE +#include + #include #include #include @@ -43,7 +45,8 @@ int syscall_init_table(void) 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]; @@ -51,7 +54,7 @@ int syscall_init_table(void) fd = kernctl_syscall_list(kernel_tracer_fd); if (fd < 0) { - ret = -errno; + ret = fd; PERROR("kernelctl syscall list"); goto error_ioctl; } @@ -76,13 +79,14 @@ int syscall_init_table(void) 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); @@ -123,7 +127,10 @@ int syscall_init_table(void) */ } - syscall_table_nb_entry = index; + /* Index starts at 0. */ + if (at_least_one_syscall) { + syscall_table_nb_entry = index + 1; + } ret = 0;