Skip to content

Commit 9c7e72c

Browse files
authored
Merge pull request ceph#57786 from Svelar/asan_cli_test
crush: avoid out-of-bound access and simplify enlarging buckets
2 parents 93ef537 + e6468f3 commit 9c7e72c

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/crush/CrushWrapper.cc

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,25 +2185,23 @@ int CrushWrapper::reclassify(
21852185

21862186
int CrushWrapper::get_new_bucket_id()
21872187
{
2188-
int id = -1;
2189-
while (crush->buckets[-1-id] &&
2190-
-1-id < crush->max_buckets) {
2191-
id--;
2192-
}
2193-
if (-1-id == crush->max_buckets) {
2194-
++crush->max_buckets;
2195-
crush->buckets = (struct crush_bucket**)realloc(
2196-
crush->buckets,
2197-
sizeof(crush->buckets[0]) * crush->max_buckets);
2198-
for (auto& i : choose_args) {
2199-
assert(i.second.size == (__u32)crush->max_buckets - 1);
2200-
++i.second.size;
2201-
i.second.args = (struct crush_choose_arg*)realloc(
2202-
i.second.args,
2203-
sizeof(i.second.args[0]) * i.second.size);
2188+
for (int index = 0; index < crush->max_buckets; index++) {
2189+
if (crush->buckets[index] == nullptr) {
2190+
return -index - 1;
22042191
}
22052192
}
2206-
return id;
2193+
++crush->max_buckets;
2194+
crush->buckets = (struct crush_bucket**)realloc(
2195+
crush->buckets,
2196+
sizeof(crush->buckets[0]) * crush->max_buckets);
2197+
for (auto& i : choose_args) {
2198+
assert(i.second.size == (__u32)crush->max_buckets - 1);
2199+
++i.second.size;
2200+
i.second.args = (struct crush_choose_arg*)realloc(
2201+
i.second.args,
2202+
sizeof(i.second.args[0]) * i.second.size);
2203+
}
2204+
return -crush->max_buckets;
22072205
}
22082206

22092207
void CrushWrapper::reweight(CephContext *cct)

0 commit comments

Comments
 (0)