|
16 | 16 | #include <xrpl/protocol/STXChainBridge.h> |
17 | 17 | #include <xrpl/protocol/jss.h> |
18 | 18 |
|
19 | | -#include <functional> |
20 | | - |
21 | 19 | namespace ripple { |
22 | 20 |
|
23 | 21 | static Expected<uint256, Json::Value> |
@@ -178,18 +176,41 @@ static Expected<STArray, Json::Value> |
178 | 176 | parseAuthorizeCredentials(Json::Value const& jv) |
179 | 177 | { |
180 | 178 | if (!jv.isArray()) |
| 179 | + { |
181 | 180 | return LedgerEntryHelpers::invalidFieldError( |
182 | 181 | "malformedAuthorizedCredentials", |
183 | 182 | jss::authorized_credentials, |
184 | 183 | "array"); |
185 | | - STArray arr(sfAuthorizeCredentials, jv.size()); |
| 184 | + } |
| 185 | + |
| 186 | + std::uint32_t const n = jv.size(); |
| 187 | + if (n > maxCredentialsArraySize) |
| 188 | + { |
| 189 | + return Unexpected(LedgerEntryHelpers::malformedError( |
| 190 | + "malformedAuthorizedCredentials", |
| 191 | + "Invalid field '" + std::string(jss::authorized_credentials) + |
| 192 | + "', array too long.")); |
| 193 | + } |
| 194 | + |
| 195 | + if (n == 0) |
| 196 | + { |
| 197 | + return Unexpected(LedgerEntryHelpers::malformedError( |
| 198 | + "malformedAuthorizedCredentials", |
| 199 | + "Invalid field '" + std::string(jss::authorized_credentials) + |
| 200 | + "', array empty.")); |
| 201 | + } |
| 202 | + |
| 203 | + STArray arr(sfAuthorizeCredentials, n); |
186 | 204 | for (auto const& jo : jv) |
187 | 205 | { |
188 | 206 | if (!jo.isObject()) |
| 207 | + { |
189 | 208 | return LedgerEntryHelpers::invalidFieldError( |
190 | 209 | "malformedAuthorizedCredentials", |
191 | 210 | jss::authorized_credentials, |
192 | 211 | "array"); |
| 212 | + } |
| 213 | + |
193 | 214 | if (auto const value = LedgerEntryHelpers::hasRequired( |
194 | 215 | jo, |
195 | 216 | {jss::issuer, jss::credential_type}, |
@@ -260,13 +281,6 @@ parseDepositPreauth(Json::Value const& dp, Json::StaticString const fieldName) |
260 | 281 | auto const arr = parseAuthorizeCredentials(ac); |
261 | 282 | if (!arr.has_value()) |
262 | 283 | return Unexpected(arr.error()); |
263 | | - if (arr->empty() || (arr->size() > maxCredentialsArraySize)) |
264 | | - { |
265 | | - return LedgerEntryHelpers::invalidFieldError( |
266 | | - "malformedAuthorizedCredentials", |
267 | | - jss::authorized_credentials, |
268 | | - "array"); |
269 | | - } |
270 | 284 |
|
271 | 285 | auto const& sorted = credentials::makeSorted(arr.value()); |
272 | 286 | if (sorted.empty()) |
|
0 commit comments