fuzz: add coverage for GetQueryParameterFromUri #35964

Open
laxmanacharya8 wants to merge 1 commit from fuzz-query-parameter into master AGit
laxmanacharya8 commented 2026-08-13 16:46:55 +00:00 (Migrated from github.com)

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.

This adds an http_query_parameter target. Besides running the parser on
arbitrary input, it round-trips a URL-encoded key/value pair back through it and
checks the cases that are easy to get wrong:

  • a parameter with no =, which is an empty value rather than a missing one
  • a repeated key, where the first occurrence wins
  • a key that occurs both before and after a #, where the parser must return
    the value found before the # and ignore the later occurrence, since
    everything 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:

FUZZ=http_query_parameter build_fuzz/bin/fuzz /tmp/corpus_http_query_parameter -runs=10000
`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. This adds an `http_query_parameter` target. Besides running the parser on arbitrary input, it round-trips a URL-encoded key/value pair back through it and checks the cases that are easy to get wrong: - a parameter with no `=`, which is an empty value rather than a missing one - a repeated key, where the first occurrence wins - a key that occurs both before and after a `#`, where the parser must return the value found before the `#` and ignore the later occurrence, since everything 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: FUZZ=http_query_parameter build_fuzz/bin/fuzz /tmp/corpus_http_query_parameter -runs=10000
DrahtBot commented 2026-08-13 16:47:03 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Stale ACK nervana21

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35964 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35964.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35964#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Stale ACK | [nervana21](https://github.com/bitcoin/bitcoin/pull/35964#pullrequestreview-4944876724) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts No conflicts as of last run. <!--5faf32d7da4f0f540f40219e4f7537a3-->
nervana21 (Migrated from github.com) reviewed 2026-08-14 18:42:33 +00:00
nervana21 (Migrated from github.com) left a comment

Concept ACK

Left a few minor suggestions. Please let me know what you think

Concept ACK Left a few minor suggestions. Please let me know what you think
nervana21 (Migrated from github.com) commented 2026-08-14 18:26:49 +00:00

ec1f8dca31238b7a5c97afc88332b27f026ab588: fuzz: add coverage for GetQueryParameterFromUri

nit: Prefer matching the style of the above and using the shortened path names.

{
   using http_bitcoin::GetQueryParameterFromUri;
ec1f8dca31238b7a5c97afc88332b27f026ab588: fuzz: add coverage for GetQueryParameterFromUri nit: Prefer matching the style of the above and using the shortened path names. ```suggestion { using http_bitcoin::GetQueryParameterFromUri; ```
nervana21 (Migrated from github.com) commented 2026-08-14 18:40:59 +00:00

ec1f8dca31238b7a5c97afc88332b27f026ab588: 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);
    // 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));
ec1f8dca31238b7a5c97afc88332b27f026ab588: 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. ```suggestion 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)); ```
nervana21 (Migrated from github.com) reviewed 2026-08-15 22:46:25 +00:00
nervana21 (Migrated from github.com) left a comment

tACK a7ecf9c83c

tACK a7ecf9c83c60622b6af9b3c992099170dd15033a
DrahtBot commented 2026-09-25 22:28:24 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-09-26 16:23:57 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/36252212318/job/108432231941
LLM reason (✨ experimental): CI failed to compile the fuzz target due to an undeclared identifier http_bitcoin in src/test/fuzz/http_request.cpp.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `ASan + LSan + UBSan + integer`: https://github.com/bitcoin/bitcoin/actions/runs/36252212318/job/108432231941</sub> <sub>LLM reason (✨ experimental): CI failed to compile the fuzz target due to an undeclared identifier `http_bitcoin` in `src/test/fuzz/http_request.cpp`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
maflcko commented 2026-09-28 06:41:31 +00:00 (Migrated from github.com)

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
No opinion on the changes here, but please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits ```sh 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
First-time contributor

Base: c8e852d3a02a73d473228232148163cdbc8f7bb0
Head: cdd6222c4fb42091ebc753915d94e8f267a8bd86

I found no actionable issues in this static review.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `c8e852d3a02a73d473228232148163cdbc8f7bb0` Head: `cdd6222c4fb42091ebc753915d94e8f267a8bd86` I found no actionable issues in this static review. [Full review report](<https://review.fish.foo/traces/35964-cdd6222c4fb42091ebc753915d94e8f267a8bd86-327-2.html>)
maflcko commented 2026-10-02 09:23:38 +00:00 (Migrated from github.com)

are you still working on this or can it be closed?

are you still working on this or can it be closed?
fanquake commented 2026-11-30 11:08:24 +00:00 (Migrated from github.com)

@marcofleon @pinheadmz you might have an opinion on these changes?

@marcofleon @pinheadmz you might have an opinion on these changes?
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35964
No description provided.