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 <darrenhsu@google.com>
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 @@
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;
}
}
}