aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexnick <alexnick@ydb.tech>2023-06-08 11:16:45 +0300
committeralexnick <alexnick@ydb.tech>2023-06-08 11:16:45 +0300
commitd36ea3261aec600e1ffe517e3c95586e3f2905aa (patch)
tree6a7490c1d470fb41d5e04df521ad7004bcaa066f
parentd07763867d1aa41dadd045c247c3ee172391afad (diff)
downloadydb-d36ea3261aec600e1ffe517e3c95586e3f2905aa.tar.gz
test and fix for out of bound array accessing
test and fix for accessing out of bound array values
-rw-r--r--ydb/core/tablet/private/aggregated_counters.cpp3
-rw-r--r--ydb/core/tablet/tablet_counters_aggregator_ut.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/ydb/core/tablet/private/aggregated_counters.cpp b/ydb/core/tablet/private/aggregated_counters.cpp
index 0416117475f..f4d0424a261 100644
--- a/ydb/core/tablet/private/aggregated_counters.cpp
+++ b/ydb/core/tablet/private/aggregated_counters.cpp
@@ -602,7 +602,8 @@ void TAggregatedLabeledCounters::FromProto(
const NKikimrLabeledCounters::TTabletLabeledCounters& labeledCounters) const {
for (const auto& counter : labeledCounters.GetLabeledCounter()) {
const ui32 nameId{counter.GetNameId()};
- if (strlen(Names[nameId]) != 0) {
+
+ if (nameId < Size() && strlen(Names[nameId]) != 0) {
// TODO: ASDFGS if CT_TIMELAG -> ctx.Now() - counters.GetValue
const bool derived = counter.GetType() == TLabeledCounterOptions::CT_DERIV;
auto namedCounter = group->GetNamedCounter("name", Names[nameId], derived);
diff --git a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
index f94a11f898f..8d9318696c1 100644
--- a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
+++ b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp
@@ -918,6 +918,12 @@ Y_UNIT_TEST_SUITE(TTabletLabeledCountersAggregator) {
UNIT_ASSERT_VALUES_EQUAL(pqCounters->GetAggregatedPerTablets().GetLabeledCounter(0).value(), 63);
UNIT_ASSERT_VALUES_EQUAL(pqCounters->GetAggregatedPerTablets().GetLabeledCounter(1).value(), 11);
+ auto additional = pqCounters->MutableAggregatedPerTablets()->AddLabeledCounter();
+ additional->SetNameId(1000);
+ additional->SetValue(13);
+ additional->SetType(TLabeledCounterOptions::CT_SIMPLE);
+ additional->SetAggregateFunc(TLabeledCounterOptions::EAF_SUM);
+
PQCounters.FromProto(counters);
}
}