From: Simon Marchi Date: Wed, 10 Nov 2021 13:39:22 +0000 (-0500) Subject: Fix: sessiond: fix possible buffer overflow warning X-Git-Tag: v2.12.7~12 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=05bd642d3bda3ac75f1b5ea1dd951f298763642f;p=lttng-tools.git Fix: sessiond: fix possible buffer overflow warning When compiling with clang-14 on Ubuntu 20.04, I get: CC lttng-syscall.lo /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/lttng-syscall.c:70:13: error: 'fscanf' may overflow; destination buffer in argument 4 has size 255, but the corresponding specifier may require size 256 [-Werror,-Wfortify-source] &index, name, &bitness) == 3) { ^ I think the compiler is right, we read a string when length up to 255 in a buffer of size 255. We need one more byte for the NULL terminator, fix that. Change-Id: I6b2eec401af3ef6230dd4b6c8559032de9b54584 Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/lttng-syscall.c b/src/bin/lttng-sessiond/lttng-syscall.c index 16eead626..b6a9a53ac 100644 --- a/src/bin/lttng-sessiond/lttng-syscall.c +++ b/src/bin/lttng-sessiond/lttng-syscall.c @@ -39,6 +39,10 @@ int syscall_init_table(int tracer_fd) uint32_t bitness; char name[SYSCALL_NAME_LEN]; +#if (SYSCALL_NAME_LEN == 255) +#define SYSCALL_NAME_LEN_SCANF_IS_A_BROKEN_API "254" +#endif + DBG3("Syscall init system call table"); fd = kernctl_syscall_list(tracer_fd); @@ -65,7 +69,7 @@ int syscall_init_table(int tracer_fd) while (fscanf(fp, "syscall { index = %zu; \ - name = %" XSTR(SYSCALL_NAME_LEN) "[^;]; \ + name = %" SYSCALL_NAME_LEN_SCANF_IS_A_BROKEN_API "[^;]; \ bitness = %u; };\n", &index, name, &bitness) == 3) { at_least_one_syscall = true;