tools/power/x86/intel-speed-select: Use null-terminated string
authorZhang Rui <rui.zhang@intel.com>
Thu, 12 Jan 2023 06:43:37 +0000 (14:43 +0800)
committerHans de Goede <hdegoede@redhat.com>
Fri, 3 Feb 2023 08:57:05 +0000 (09:57 +0100)
strlen() and strtok() takes null-termimated strings as input.
Make sure these strings are null-terminated before using them.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
tools/power/x86/intel-speed-select/isst-config.c

index b5822ee..b549e6f 100644 (file)
@@ -1583,6 +1583,7 @@ static int set_cpufreq_scaling_min_max_from_cpuinfo(int cpu, int cpuinfo_max, in
        if (fd < 0)
                return fd;
 
+       min_freq[15] = '\0';
        len = strlen(min_freq);
        ret = write(fd, min_freq, len);
        if (ret == -1) {
@@ -2015,6 +2016,7 @@ static void set_fact_enable(int arg)
                        if (len < 0)
                                continue;
 
+                       sibling_list[127] = '\0';
                        cpu_str = strtok(sibling_list, ",");
                        while (cpu_str != NULL) {
                                int cpu;