From bb6e798cb47c1a16dbeaae168903ae9760838815 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Wed, 27 Jul 2022 10:54:53 -0400 Subject: [PATCH] fix: removed accidental VLA in _get_num_possible_cpus() The LTTNG_UST_PAGE_SIZE define can either point to a literal value or the sysconf() function making buf[] a VLA. Replace this by a cpumask specifc define that will always be a literal value. Change-Id: I8d329f314878e8018939f979861918969e3ec8ac Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- libringbuffer/smp.c | 6 +++--- libringbuffer/smp.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libringbuffer/smp.c b/libringbuffer/smp.c index 8b66b9e8..966556dc 100644 --- a/libringbuffer/smp.c +++ b/libringbuffer/smp.c @@ -30,6 +30,7 @@ #include #include +#include "align.h" #include "smp.h" #include "usterr-signal-safe.h" @@ -206,11 +207,10 @@ error: void _get_num_possible_cpus(void) { int ret; - int buf_len = sysconf(_SC_PAGE_SIZE); - char buf[buf_len]; + char buf[LTTNG_UST_CPUMASK_SIZE]; /* Get the possible cpu mask from sysfs, fallback to sysconf. */ - ret = get_possible_cpu_mask_from_sysfs((char *) &buf, buf_len); + ret = get_possible_cpu_mask_from_sysfs((char *) &buf, LTTNG_UST_CPUMASK_SIZE); if (ret <= 0) goto fallback; diff --git a/libringbuffer/smp.h b/libringbuffer/smp.h index 1a880994..0db9e841 100644 --- a/libringbuffer/smp.h +++ b/libringbuffer/smp.h @@ -31,6 +31,8 @@ extern int __num_possible_cpus; +#define LTTNG_UST_CPUMASK_SIZE 4096 + /* * Get the CPU possible mask string from sysfs. * -- 2.34.1