x86_energy_perf_policy: Use calloc to initialize string buffer

strstr was being run on a potentially unterminated buffer.

Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Len Brown 2026-05-23 18:37:20 -04:00
parent febae602a5
commit d833146644

View File

@ -784,10 +784,10 @@ void err_on_hypervisor(void)
/* On VMs /proc/cpuinfo contains a "flags" entry for hypervisor */
cpuinfo = fopen_or_die("/proc/cpuinfo", "r");
buffer = malloc(4096);
buffer = calloc(4096, 1);
if (!buffer) {
fclose(cpuinfo);
err(-ENOMEM, "buffer malloc fail");
err(-ENOMEM, "buffer calloc fail");
}
if (!fread(buffer, 1024, 1, cpuinfo)) {
@ -816,11 +816,10 @@ void err_on_hypervisor(void)
fclose(cpuinfo);
hypervisor = strstr(buffer, "hypervisor");
free(buffer);
if (hypervisor)
err(-1, "not supported on this virtual machine");
free(buffer);
}
/*