From 05784ada94f31ecfc1f64ef851af197ca3a172e5 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 25 Feb 2021 08:45:55 +0000 Subject: Add proper range checking when identifying CPU capabilities Partially Resolves: COMPMID-4174 Signed-off-by: Georgios Pinitas Change-Id: I4546440dfb60d6b3d80e31a0388be96d46539989 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5178 Reviewed-by: SiCong Li Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- src/runtime/CPUUtils.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/runtime/CPUUtils.cpp b/src/runtime/CPUUtils.cpp index 6f51ee62ed..63c9a8639c 100644 --- a/src/runtime/CPUUtils.cpp +++ b/src/runtime/CPUUtils.cpp @@ -220,8 +220,9 @@ void populate_models_cpuinfo(std::vector &cpusv) if(file.is_open()) { std::string line; - int midr = 0; - int curcpu = -1; + int midr = 0; + int curcpu = -1; + const int num_cpus = static_cast(cpusv.size()); while(bool(getline(file, line))) { @@ -238,10 +239,14 @@ void populate_models_cpuinfo(std::vector &cpusv) return; } - if(curcpu >= 0) + if(curcpu >= 0 && curcpu < num_cpus) { cpusv[curcpu] = midr_to_model(midr); } + else + { + ARM_COMPUTE_LOG_INFO_MSG_CORE("Trying to populate a core id with id greater than the expected number of cores!"); + } midr = 0; curcpu = newcpu; @@ -291,7 +296,7 @@ void populate_models_cpuinfo(std::vector &cpusv) } } - if(curcpu >= 0 && curcpu < static_cast(cpusv.size())) + if(curcpu >= 0 && curcpu < num_cpus) { cpusv[curcpu] = midr_to_model(midr); } -- cgit v1.2.1