diff options
author | Jiaqing Zhao <jiaqing.zhao@intel.com> | 2022-06-24 12:54:29 +0300 |
---|---|---|
committer | Jiaqing Zhao <jiaqing.zhao@intel.com> | 2022-07-21 08:59:49 +0300 |
commit | ce8ea743055f1b82c60790db40aa3295e03bdf9c (patch) | |
tree | f67b32d500218192f8fa5c5f4101a3bc844b911c | |
parent | a926c53e9ceb83ea5dd02f889ef6ba1f2ad358f3 (diff) | |
download | bmcweb-ce8ea743055f1b82c60790db40aa3295e03bdf9c.tar.xz |
query_param: Set default value of $top to maxEntriesPerPage
Current code initializes $top to std::numeric_limits<size_t>::max(),
when adding with a non-zero $skip value, it overflows. This patch
solves this issue by initializing it to maxEntriesPerPage.
Fixes c937d2b ("Make log services use parameter delegation").
Tested:
Verified providing only $skip in the query parameter in /redfish/v1
/Systems/system/LogServices/EventLog/Entries is properly handled.
Change-Id: Id5668cecda97a78f803941d6eb2e1aa0ba9495aa
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
-rw-r--r-- | redfish-core/include/utils/query_param.hpp | 8 | ||||
-rw-r--r-- | redfish-core/include/utils/query_param_test.cpp | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp index 889a684798..0e86ec5934 100644 --- a/redfish-core/include/utils/query_param.hpp +++ b/redfish-core/include/utils/query_param.hpp @@ -16,6 +16,7 @@ namespace redfish { namespace query_param { +inline constexpr size_t maxEntriesPerPage = 1000; enum class ExpandType : uint8_t { @@ -38,7 +39,7 @@ struct Query size_t skip = 0; // Top - size_t top = std::numeric_limits<size_t>::max(); + size_t top = maxEntriesPerPage; }; // The struct defines how resource handlers in redfish-core/lib/ can handle @@ -87,7 +88,7 @@ inline Query delegate(const QueryCapabilities& queryCapabilities, Query& query) if (queryCapabilities.canDelegateTop) { delegated.top = query.top; - query.top = std::numeric_limits<size_t>::max(); + query.top = maxEntriesPerPage; } // delegate skip @@ -174,7 +175,6 @@ inline QueryError getSkipParam(std::string_view value, Query& query) return getNumericParam(value, query.skip); } -static constexpr size_t maxEntriesPerPage = 1000; inline QueryError getTopParam(std::string_view value, Query& query) { QueryError ret = getNumericParam(value, query.top); @@ -607,7 +607,7 @@ inline void return; } - if (query.top != std::numeric_limits<size_t>::max() || query.skip != 0) + if (query.top <= maxEntriesPerPage || query.skip != 0) { processTopAndSkip(query, intermediateResponse); } diff --git a/redfish-core/include/utils/query_param_test.cpp b/redfish-core/include/utils/query_param_test.cpp index 7520f3e367..077447f626 100644 --- a/redfish-core/include/utils/query_param_test.cpp +++ b/redfish-core/include/utils/query_param_test.cpp @@ -75,7 +75,7 @@ TEST(Delegate, TopNegative) .top = 42, }; Query delegated = delegate(QueryCapabilities{}, query); - EXPECT_EQ(delegated.top, std::numeric_limits<size_t>::max()); + EXPECT_EQ(delegated.top, maxEntriesPerPage); EXPECT_EQ(query.top, 42); } @@ -89,7 +89,7 @@ TEST(Delegate, TopPositive) }; Query delegated = delegate(capabilities, query); EXPECT_EQ(delegated.top, 42); - EXPECT_EQ(query.top, std::numeric_limits<size_t>::max()); + EXPECT_EQ(query.top, maxEntriesPerPage); } TEST(Delegate, SkipNegative) |