mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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:
parent
febae602a5
commit
d833146644
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user