BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlat_fuzzutil

Detailed Description

Provide fuzz test utilities for bdlat-types.

Outline

Purpose

Provide fuzz test utilities for bdlat-types.

Classes

See also
bslim_fuzzdataview, bslim_fuzzutil

Description

This component provides a namespace, bdlat::FuzzUtil, containing functions that create bdlat message types from fuzz data provided by a fuzz harness (e.g., libFuzzer).

Effectively, given a random sequence of bytes provided by a fuzz harness, like libFuzzer, this component can be used to populate a bdlat-compatible message with arbitrary data determined by that random sequence. This can be used to fuzz test an interface (like a service interface) taking a bdlat-compatible message. See the BDE fuzz-testing guide for more detail.

Usage

This section illustrates intended use of this component.

Example 1: Creating a Message

Suppose we have a message type MyMessage and we wish to fuzz test it.

We have to provide a function like this for libFuzzer:

extern "C"
int LLVMFuzzerTestOneInput(const uint8_t *bytes, size_t size)
{
bslim::FuzzDataView fuzzData(bytes, size);
MyMessage msg;
// Use `msg`...
return 0;
}
static void consumeMessage(t_MESSAGE *message, bslim::FuzzDataView *fuzzData)
Definition bdlat_fuzzutil.h:608
Definition bslim_fuzzdataview.h:130

After the FuzzUtil::consumeMessage call, the msg object contains a well-formed message, which can then be serialized or processed in another way.