BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslim_fuzzdataview

Detailed Description

Outline

Purpose

Provide a view of a buffer of fuzz data bytes.

Classes

See also
bslim_fuzzutil

Description

This component defines a reference-semantic class, bslim::FuzzDataView, providing a view to a non-modifiable buffer of fuzz data obtained from a fuzz testing harness (e.g., libFuzzer).

See {http://bburl/BDEFuzzTesting} for details on how to build and run with fuzz testing enabled.

Typically, this class is intended to be employed by a utility that takes an object of this class as an in-out parameter, consumes the bytes (updating the view so that the bytes are not used again), and returns objects of the type requested.

Usage

This section illustrates intended use of this component.

Example 1: Creating a bsl::string

The following example demonstrates how to create a bsl::string object from a FuzzDataView.

First, we construct a FuzzDataView object, view0, from an array of bytes:

const bsl::uint8_t data[] = {0x8A, 0x19, 0x0D, 0x44, 0x37, 0x0D,
0x38, 0x5E, 0x9B, 0xAA, 0xF3, 0xDA};
bslim::FuzzDataView view0(data, sizeof(data));
assert(12 == view0.length());
Definition bslim_fuzzdataview.h:130

Next, we take the first 3 bytes from view0 and store them in a new FuzzDataView object, view1:

assert(3 == view1.length());
assert(9 == view0.length());
FuzzDataView removePrefix(bsl::size_t numBytes)
Definition bslim_fuzzdataview.h:205
bsl::size_t length() const
Return the length in bytes of the buffer.
Definition bslim_fuzzdataview.h:240

We confirm that removePrefix(3) removed 3 bytes from view0 and that view1 has length 3.

Then, we create a bsl::string object from view1:

bsl::string s1(view1.begin(), view1.end());
assert(3 == s1.length());
Definition bslstl_string.h:1281
const bsl::uint8_t * end() const
Return a const pointer to the end of the buffer.
Definition bslim_fuzzdataview.h:234
const bsl::uint8_t * begin() const
Return a const pointer to the beginning of the buffer.
Definition bslim_fuzzdataview.h:228

Finally, we create another bsl::string with the remaining bytes of view0:

bsl::string s2(view0.begin(), view0.end());
assert(9 == s2.length());