Provide a view of a buffer of fuzz data bytes.
More...
Namespaces |
namespace | bslim |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a view of a buffer of fuzz data bytes.
-
- Classes:
-
- See also:
- Component 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());
Next, we take the first 3 bytes from view0
and store them in a new FuzzDataView
object, view1
: 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
: Finally, we create another bsl::string
with the remaining bytes of view0
: bsl::string s2(view0.begin(), view0.end());
assert(9 == s2.length());