Skip to content

Commit

Permalink
Merge pull request #318 from amirlivneh/fuzz-request
Browse files Browse the repository at this point in the history
fuzz_http3serverreq: Send requests
  • Loading branch information
tatsuhiro-t authored Jan 16, 2025
2 parents 6274305 + 53fc7a6 commit a3a7237
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions fuzz/fuzz_http3serverreq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,39 @@ int send_data(nghttp3_conn *conn) {
}
}; // namespace

namespace {
int send_requests(nghttp3_conn *conn,
FuzzedDataProvider &fuzzed_data_provider) {
for (; fuzzed_data_provider.ConsumeBool();) {
auto stream_id = fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(
0, NGHTTP3_MAX_VARINT);
if (!nghttp3_client_stream_bidi(stream_id)) {
continue;
}

auto name = fuzzed_data_provider.ConsumeRandomLengthString();
auto value = fuzzed_data_provider.ConsumeRandomLengthString();

const nghttp3_nv nva[] = {
{
.name = reinterpret_cast<uint8_t *>(const_cast<char *>(name.c_str())),
.value = reinterpret_cast<uint8_t *>(const_cast<char *>(value.c_str())),
.namelen = name.size(),
.valuelen = value.size(),
},
};

auto rv = nghttp3_conn_submit_request(
conn, stream_id, nva, nghttp3_arraylen(nva), nullptr, nullptr);
if (rv != 0) {
return rv;
}
}

return 0;
}
}; // namespace

namespace {
int shutdown_streams(nghttp3_conn *conn,
FuzzedDataProvider &fuzzed_data_provider) {
Expand Down Expand Up @@ -367,6 +400,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
goto fin;
}

if (!server) {
auto rv = send_requests(conn, fuzzed_data_provider);
if (rv != 0) {
goto fin;
}
}

auto chunk_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
auto chunk = fuzzed_data_provider.ConsumeBytes<uint8_t>(chunk_size);
auto fin = fuzzed_data_provider.ConsumeBool();
Expand Down

0 comments on commit a3a7237

Please sign in to comment.