libtimeinstate: fix bug when cpu count exceeds CPUS_PER_ENTRY
In getUidCpuFreqTimes() and getUidConcurrentTimes(), in the case where
findMapEntry fails but getFirstMapKey succeeds we overwrite key and
then continue to the next loop iteration. This can cause problems when
gNCpus > CPUS_PER_ENTRY causing us to use multiple buckets: in both
functions, subsequent loop iterations could use the wrong UID, and in
getUidConcurrentTimes() we can enter an infinite loop if
getFirstMapKey() overwrites key.bucket with a lower value.
Instead, use a separate time_key_t variable for the call to
getFirstMapKey(). To prevent similar bugs, make key a const variable
scoped to a single loop iteration.
Bug: 229788490
Test: libtimeinstate_test
Signed-off-by:
Connor O'Brien <connoro@google.com>
Change-Id: I491aa3bf4c5bce9218bdc44a5eee6ea426b151ae
Loading
Please register or sign in to comment