From: Jan Beulich Date: Thu, 27 Mar 2025 14:04:48 +0000 (+0100) Subject: xenpm: sanitize allocations in show_cpufreq_para_by_cpuid() X-Git-Tag: RELEASE-4.19.2~24 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=748be9a974d95056763828bbb2572fdbc7b71ef7;p=xen.git xenpm: sanitize allocations in show_cpufreq_para_by_cpuid() malloc(), when passed zero size, may return NULL (the behavior is implementation defined). Mirror the ->gov_num check to the other two allocations as well. Don't chance then actually using a NULL in print_cpufreq_para(). Fixes: 75e06d089d48 ("xenpm: add cpu frequency control interface, through which user can") Signed-off-by: Jan Beulich Acked-by: Andrew Cooper Reviewed-by: Jason Andryuk master commit: 6c0dc87bb0e08fb31a68bf4c4149a18b92628f14 master date: 2025-03-26 12:30:57 +0100 --- diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 336d246346..db658ebadd 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -840,8 +840,9 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) } else { - printf("scaling_avail_gov : %s\n", - p_cpufreq->scaling_available_governors); + if ( p_cpufreq->gov_num ) + printf("scaling_avail_gov : %s\n", + p_cpufreq->scaling_available_governors); printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); if ( !strncmp(p_cpufreq->u.s.scaling_governor, @@ -907,7 +908,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) p_cpufreq->scaling_available_frequencies = NULL; p_cpufreq->scaling_available_governors = NULL; - if (!(p_cpufreq->affected_cpus = + if (p_cpufreq->cpu_num && + !(p_cpufreq->affected_cpus = malloc(p_cpufreq->cpu_num * sizeof(uint32_t)))) { fprintf(stderr, @@ -916,7 +918,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) ret = -ENOMEM; goto out; } - if (!(p_cpufreq->scaling_available_frequencies = + if (p_cpufreq->freq_num && + !(p_cpufreq->scaling_available_frequencies = malloc(p_cpufreq->freq_num * sizeof(uint32_t)))) { fprintf(stderr,