From d094ba620f0fb5e2842c03ae2df1eee6664845f3 Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Tue, 7 Feb 2023 10:45:26 +0800 Subject: [PATCH] powerstats: fix buffer underflow issue in CPUPM data provider Bug: 267827563 Test: dumpsys android.hardware.power.stats.IPowerStats/default Change-Id: I569a20f250c7ca3586f71084918022f04d6693d4 Signed-off-by: Darren Hsu --- .../CpupmStateResidencyDataProvider.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/powerstats/CpupmStateResidencyDataProvider.cpp b/powerstats/CpupmStateResidencyDataProvider.cpp index bb0e61f..c963f78 100644 --- a/powerstats/CpupmStateResidencyDataProvider.cpp +++ b/powerstats/CpupmStateResidencyDataProvider.cpp @@ -100,19 +100,21 @@ bool CpupmStateResidencyDataProvider::getStateResidencies( stateId = temp; } - if (stateId >= 0) { - entityIndex = matchEntity(line); - it = residencies->find(mConfig.entities[entityIndex].first); + if (stateId < 0) continue; - if (it != residencies->end()) { - if (parseState(line, &duration, &count)) { - it->second[stateId].totalTimeInStateMs = duration / US_TO_MS; - it->second[stateId].totalStateEntryCount = count; - } else { - LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line) - << "]"; - return false; - } + entityIndex = matchEntity(line); + + if (entityIndex < 0) continue; + + it = residencies->find(mConfig.entities[entityIndex].first); + if (it != residencies->end()) { + if (parseState(line, &duration, &count)) { + it->second[stateId].totalTimeInStateMs = duration / US_TO_MS; + it->second[stateId].totalStateEntryCount = count; + } else { + LOG(ERROR) << "Failed to parse duration and count from [" << std::string(line) + << "]"; + return false; } } }