|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] xenpm: sanitize allocations in show_cpufreq_para_by_cpuid()
malloc(), when passed zero size, may return NULL (the behavior is
implementation defined). Extend 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 <jbeulich@xxxxxxxx>
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -840,8 +840,9 @@ static void print_cpufreq_para(int cpuid
}
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
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
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,
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |