fix: removed accidental VLA in _get_num_possible_cpus()
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 27 Jul 2022 14:54:53 +0000 (10:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 27 Jul 2022 15:22:20 +0000 (11:22 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/smp.c
src/common/smp.h

index d7ba23c4f263b2afec7fd906f2cc525fbd745dbd..980947cf4de9431880494a0d55914811ec974bd0 100644 (file)
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <unistd.h>
 #include <pthread.h>
 #include <stdlib.h>
 
 #include <urcu/compiler.h>
 
 #include <unistd.h>
 #include <pthread.h>
 #include <stdlib.h>
 
 #include <urcu/compiler.h>
 
-#include "common/align.h"
 #include "common/logging.h"
 #include "common/smp.h"
 
 #include "common/logging.h"
 #include "common/smp.h"
 
@@ -190,11 +190,10 @@ error:
 static void _get_num_possible_cpus(void)
 {
        int ret;
 static void _get_num_possible_cpus(void)
 {
        int ret;
-       int buf_len = LTTNG_UST_PAGE_SIZE;
-       char buf[buf_len];
+       char buf[LTTNG_UST_CPUMASK_SIZE];
 
        /* Get the possible cpu mask from sysfs, fallback to sysconf. */
 
        /* 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;
 
        if (ret <= 0)
                goto fallback;
 
index b6dd5707819af414a4c4a203e1e3d998ad983cf3..51fbd2d7e5d34c01c04df7d13ac4397302a223c0 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef _UST_COMMON_SMP_H
 #define _UST_COMMON_SMP_H
 
 #ifndef _UST_COMMON_SMP_H
 #define _UST_COMMON_SMP_H
 
+#define LTTNG_UST_CPUMASK_SIZE 4096
+
 /*
  * Get the CPU possible mask string from sysfs.
  *
 /*
  * Get the CPU possible mask string from sysfs.
  *
This page took 0.027713 seconds and 4 git commands to generate.