Skip to content

fuzz: add coverage for GetQueryParameterFromUri - #35964

Open
laxmanacharya8 wants to merge 1 commit into
bitcoin:masterfrom
laxmanacharya8:fuzz-query-parameter
Open

laxmanacharya8 wants to merge 1 commit into
bitcoin:masterfrom
laxmanacharya8:fuzz-query-parameter

Conversation

@laxmanacharya8

Copy link
Copy Markdown
Contributor

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

DrahtBot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

@nervana21 nervana21 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

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

}

FUZZ_TARGET(http_query_parameter)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ec1f8dc: fuzz: add coverage for GetQueryParameterFromUri

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

Suggested change
{
{
using http_bitcoin::GetQueryParameterFromUri;

Comment thread src/test/fuzz/http_request.cpp Outdated
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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));

@nervana21 nervana21 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK a7ecf9c

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 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.

@maflcko

maflcko commented Sep 28, 2026

Copy link
Copy Markdown
Member

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

@maflcko

maflcko commented Oct 2, 2026

Copy link
Copy Markdown
Member

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

@DrahtBot
DrahtBot marked this pull request as draft October 2, 2026 09:24
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.
@laxmanacharya8
laxmanacharya8 marked this pull request as ready for review October 3, 2026 06:09
@DrahtBot DrahtBot removed the CI failed label Oct 3, 2026
@fanquake

Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants