8000 fix UB in DistributeExecutor (#14774) · arangodb/arangodb@fef43cc · GitHub
[go: up one dir, main page]

Skip to content

Commit fef43cc

Browse files
authored
fix UB in DistributeExecutor (#14774)
* fix UB in DistributeExecutor * remove comment
1 parent aa9c736 commit fef43cc

File tree

2 files changed

+30
-43
lines changed

2 files changed

+30
-43
lines changed

arangod/Aql/DistributeExecutor.cpp

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,37 @@ auto DistributeExecutor::distributeBlock(SharedAqlItemBlockPtr const& block, Ski
125125
choosenMap[key].emplace_back(i);
126126
}
127127
} else {
128-
auto input = extractInput(block, i);
129-
if (!input.isNone()) {
130-
// NONE is ignored.
131-
// Object is processd
132-
// All others throw.
133-
TRI_ASSERT(input.isObject());
134-
if (_infos.shouldDistributeToAll(input)) {
135-
// This input should be added to all clients
136-
for (auto const& [key, value] : blockMap) {
137-
choosenMap[key].emplace_back(i);
138-
}
139-
} else {
140-
auto client = getClient(input);
141-
if (!client.empty()) {
142-
// We can only have clients we are prepared for
143-
TRI_ASSERT(blockMap.find(client) != blockMap.end());
144-
choosenMap[client].emplace_back(i);
128+
// check first input register
129+
AqlValue val = InputAqlItemRow{block, i}.getValue(_infos.registerId());
130+
131+
VPackSlice input = val.slice(); // will throw when wrong type
132+
if (input.isNone()) {
133+
continue;
134+
}
135+
136+
if (!input.isObject()) {
137+
THROW_ARANGO_EXCEPTION_MESSAGE(
138+
TRI_ERROR_INTERNAL, "DistributeExecutor requires an object as input");
139+
}
140+
// NONE is ignored.
141+
// Object is processd
142+
// All others throw.
143+
TRI_ASSERT(input.isObject());
144+
if (_infos.shouldDistributeToAll(input)) {
145+
// This input should be added to all clients
146+
for (auto const& [key, value] : blockMap) {
147+
choosenMap[key].emplace_back(i);
148+
}
149+
} else {
150+
auto client = getClient(input);
151+
if (!client.empty()) {
152+
// We can only have clients we are prepared for
153+
TRI_ASSERT(blockMap.find(client) != blockMap.end());
154+
if (ADB_UNLIKELY(blockMap.find(client) == blockMap.end())) {
155+
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
156+
std::string("unexpected client id '") + client + "' found in blockMap");
145157
}
158+
choosenMap[client].emplace_back(i);
146159
}
147160
}
148161
}
@@ -168,23 +181,6 @@ auto DistributeExecutor::distributeBlock(SharedAqlItemBlockPtr const& block, Ski
168181
}
169182
}
170183

171-
auto DistributeExecutor::extractInput(SharedAqlItemBlockPtr const& block,
172-
size_t rowIndex) const -> VPackSlice {
173-
// check first input register
174-
AqlValue val = InputAqlItemRow{block, rowIndex}.getValue(_infos.registerId());
175-
176-
VPackSlice input = val.slice(); // will throw when wrong type
177-
if (input.isNone()) {
178-
return input;
179-
}
180-
181-
if (!input.isObject()) {
182-
THROW_ARANGO_EXCEPTION_MESSAGE(
183-
TRI_ERROR_INTERNAL, "DistributeExecutor requires an object as input");
184-
}
185-
return input;
186-
}
187-
188184
auto DistributeExecutor::getClient(VPackSlice input) const -> std::string {
189185
auto res = _infos.getResponsibleClient(input);
190186
if (res.fail()) {

arangod/Aql/DistributeExecutor.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,8 @@ class DistributeExecutor {
9797
std::unordered_map<std::string, ClientBlockData>& blockMap) -> void;
9898

9999
private:
100-
/**
101-
* @brief Compute which client needs to get this row
102-
* @param block The input block
103-
* @param rowIndex
104-
* @return std::string Identifier used by the client
105-
*/
106-
auto extractInput(SharedAqlItemBlockPtr const& block, size_t rowIndex) const
107-
-> velocypack::Slice;
108100
auto getClient(velocypack::Slice input) const -> std::string;
109101

110-
private:
111102
DistributeExecutorInfos const& _infos;
112103

113104
// a reusable Builder object for building _key values

0 commit comments

Comments
 (0)
0