OSDN Git Service

Fix statsd ASAN failure
authorYi Kong <yikong@google.com>
Thu, 8 Aug 2019 00:02:22 +0000 (17:02 -0700)
committerYi Kong <yikong@google.com>
Thu, 8 Aug 2019 22:09:09 +0000 (22:09 +0000)
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

index b29e979..8233eee 100644 (file)
@@ -35,8 +35,14 @@ void StatsPuller::SetUidMap(const sp<UidMap>& 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<std::shared_ptr<LogEvent>>* data) {