From 3ee963917f05b00b888ce4a6fc6b3df0a190a1c4 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Wed, 7 Aug 2019 17:02:22 -0700 Subject: [PATCH] Fix statsd ASAN failure If tagId is not found in kAllPullAtomInfo map, StatsPuller will read outside of the object. Add a condition check to gracefully handle unrecognised tagId and fix the ASAN failure. Bug: 139037732 Test: boot aosp_x86-eng Change-Id: Ic62b89866dbec82f05e6f8e6afca9b312f44a801 Merged-In: I5db561c4223efc4ef6b1441490d319cc6ec8afc7 Exempt-From-Owner-Approval: trivial change, owner OOO. --- cmds/statsd/src/external/StatsPuller.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmds/statsd/src/external/StatsPuller.cpp b/cmds/statsd/src/external/StatsPuller.cpp index b29e979b5236..8233eeec06c7 100644 --- a/cmds/statsd/src/external/StatsPuller.cpp +++ b/cmds/statsd/src/external/StatsPuller.cpp @@ -35,8 +35,14 @@ void StatsPuller::SetUidMap(const sp& uidMap) { mUidMap = uidMap; } // ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently StatsPuller::StatsPuller(const int tagId) : mTagId(tagId) { - mCoolDownNs = StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId)->second.coolDownNs; - VLOG("Puller for tag %d created. Cooldown set to %lld", mTagId, (long long)mCoolDownNs); + auto pullAtomInfo = StatsPullerManagerImpl::kAllPullAtomInfo.find(tagId); + if (pullAtomInfo != StatsPullerManagerImpl::kAllPullAtomInfo.end()) { + mCoolDownNs = pullAtomInfo->second.coolDownNs; + VLOG("Puller for tag %d created. Cooldown set to %lld", mTagId, (long long)mCoolDownNs); + } else { + mCoolDownNs = 0; + VLOG("Creating puller for a non-recognised tag %d.", mTagId); + } } bool StatsPuller::Pull(const int64_t elapsedTimeNs, std::vector>* data) { -- 2.11.0