Repository navigation
fuzz: add coverage for GetQueryParameterFromUri - #35964
laxmanacharya8 wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
nervana21
left a comment
There was a problem hiding this comment.
Concept ACK
Left a few minor suggestions. Please let me know what you think
| } | ||
|
|
||
| FUZZ_TARGET(http_query_parameter) | ||
| { |
There was a problem hiding this comment.
ec1f8dc: fuzz: add coverage for GetQueryParameterFromUri
nit: Prefer matching the style of the above and using the shortened path names.
| { | |
| { | |
| using http_bitcoin::GetQueryParameterFromUri; |
| assert(http_bitcoin::GetQueryParameterFromUri(query_uri, key) == value); | ||
| assert(http_bitcoin::GetQueryParameterFromUri("/endpoint?" + encoded_key, key) == ""); | ||
| assert(http_bitcoin::GetQueryParameterFromUri(query_uri + "&" + encoded_key + "=ignored", key) == value); | ||
| assert(http_bitcoin::GetQueryParameterFromUri(query_uri + "#?" + encoded_key + "=ignored", key) == value); |
There was a problem hiding this comment.
ec1f8dc: fuzz: add coverage for GetQueryParameterFromUri
The PR text states that this proves we "ignore the later occurrence" after #. However, because an identical key name sits before #, the first match wins and treating # like & still passes. In order to prove that statement, I think we need a lookup whose key exists only after #.
The ? character must precede # and the dummy name cannot match key name.
| assert(http_bitcoin::GetQueryParameterFromUri(query_uri + "#?" + encoded_key + "=ignored", key) == value); | |
| assert(http_bitcoin::GetQueryParameterFromUri(query_uri + "#?" + encoded_key + "=ignored", key) == value); | |
| // First '?' must precede '#', and this name must not be key. | |
| const std::string dummy{key == "n" ? "m" : "n"}; | |
| assert(!GetQueryParameterFromUri("/endpoint?" + dummy + "=1#?" + encoded_key + "=" + encoded_value, key)); |
ec1f8dc to
a7ecf9c
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
No opinion on the changes here, but please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits git fetch upstream && git merge upstream/master # Make sure we are on current master
git reset --soft upstream/master && git commit -m 'bla: Fix ...' # Squash everything into a single commit
git push origin master -f # Force push |
|
are you still working on this or can it be closed? |
GetQueryParameterFromUri() parses the query string of a request target supplied by a remote client. It is reached from the REST interface for the "count", "offset", "size", "verbose" and "mempool_sequence" parameters, but had no fuzz coverage.
d7c06f7 to
cdd6222
Compare
|
@marcofleon @pinheadmz you might have an opinion on these changes? |

GetQueryParameterFromUri()parses the query string of a request targetsupplied by a remote client. It is reached from the REST interface for the
count,offset,size,verboseandmempool_sequenceparameters, but hadno fuzz coverage.
This adds an
http_query_parametertarget. Besides running the parser onarbitrary input, it round-trips a URL-encoded key/value pair back through it and
checks the cases that are easy to get wrong:
=, which is an empty value rather than a missing one#, where the parser must returnthe value found before the
#and ignore the later occurrence, sinceeverything from the fragment separator onwards is not part of the query
string
Testing
Built the fuzz binary and ran the new target against a temporary corpus
directory, capped at 10,000 executions: