Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Macros | Typedefs | Functions
fuzz.h File Reference
#include <cstdint>
#include <functional>
#include <span>
#include <string_view>
Include dependency graph for fuzz.h:

Go to the source code of this file.

Classes

struct  FuzzTargetOptions
 

Macros

#define LIMITED_WHILE(condition, limit)    for (unsigned _count{limit}; (condition) && _count; --_count)
 Can be used to limit a theoretically unbounded loop. More...
 
#define FUZZ_TARGET(...)   DETAIL_FUZZ(__VA_ARGS__)
 
#define DETAIL_FUZZ(name, ...)
 

Typedefs

using FuzzBufferType = std::span< const uint8_t >
 
using TypeTestOneInput = std::function< void(FuzzBufferType)>
 

Functions

void FuzzFrameworkRegisterTarget (std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts)
 

Macro Definition Documentation

◆ DETAIL_FUZZ

#define DETAIL_FUZZ (   name,
  ... 
)
Value:
void name##_fuzz_target(FuzzBufferType); \
struct name##_Before_Main { \
name##_Before_Main() \
{ \
FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, {__VA_ARGS__}); \
} \
} const static g_##name##_before_main; \
void name##_fuzz_target(FuzzBufferType buffer)
std::span< const uint8_t > FuzzBufferType
Definition: fuzz.h:25
const char * name
Definition: rest.cpp:49

Definition at line 37 of file fuzz.h.

◆ FUZZ_TARGET

#define FUZZ_TARGET (   ...)    DETAIL_FUZZ(__VA_ARGS__)

Definition at line 35 of file fuzz.h.

◆ LIMITED_WHILE

#define LIMITED_WHILE (   condition,
  limit 
)     for (unsigned _count{limit}; (condition) && _count; --_count)

Can be used to limit a theoretically unbounded loop.

This caps the runtime to avoid timeouts or OOMs.

This can be used in combination with a check in the condition to confirm whether the fuzz engine provided "good" data. If the fuzz input contains invalid data, the loop aborts early. This will teach the fuzz engine to look for useful data and avoids bloating the fuzz input folder with useless data.

Definition at line 22 of file fuzz.h.

Typedef Documentation

◆ FuzzBufferType

using FuzzBufferType = std::span<const uint8_t>

Definition at line 25 of file fuzz.h.

◆ TypeTestOneInput

using TypeTestOneInput = std::function<void(FuzzBufferType)>

Definition at line 27 of file fuzz.h.

Function Documentation

◆ FuzzFrameworkRegisterTarget()

void FuzzFrameworkRegisterTarget ( std::string_view  name,
TypeTestOneInput  target,
FuzzTargetOptions  opts 
)

Definition at line 73 of file fuzz.cpp.

Here is the call graph for this function: