From 064abd14a55e0fa1bff530237816a748d01e0ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20G=C3=B6gge?= Date: Wed, 22 Dec 2021 20:47:53 +0100 Subject: [PATCH] [rest] add a more verbose error message for invalid header counts --- src/rest.cpp | 4 ++-- test/functional/interface_rest.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rest.cpp b/src/rest.cpp index 65033c6c960..eb661c94c6e 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -195,7 +195,7 @@ static bool rest_headers(const std::any& context, const auto parsed_count{ToIntegral(path[0])}; if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) { - return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0])); + return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0])); } std::string hashStr = path[1]; @@ -371,7 +371,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const const auto parsed_count{ToIntegral(uri_parts[1])}; if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) { - return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1])); + return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1])); } std::vector headers; diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 9cb452e9c00..8f6743d97c3 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -279,7 +279,7 @@ class RESTTest (BitcoinTestFramework): # Test number parsing for num in ['5a', '-5', '0', '2001', '99999999999999999999999999999999999']: assert_equal( - bytes(f'Header count out of acceptable range (1-2000): {num}\r\n', 'ascii'), + bytes(f'Header count is invalid or out of acceptable range (1-2000): {num}\r\n', 'ascii'), self.test_rest_request(f"/headers/{num}/{bb_hash}", ret_type=RetType.BYTES, status=400), )