Rizin
unix-like reverse engineering framework and cli tools
fuzz_helpers.h File Reference
#include "fuzz.h"
#include "xxhash.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "lz4.c"

Go to the source code of this file.

Macros

#define LZ4_COMMONDEFS_ONLY
 
#define MIN(a, b)   ( (a) < (b) ? (a) : (b) )
 
#define MAX(a, b)   ( (a) > (b) ? (a) : (b) )
 
#define FUZZ_QUOTE_IMPL(str)   #str
 
#define FUZZ_QUOTE(str)   FUZZ_QUOTE_IMPL(str)
 
#define FUZZ_ASSERT_MSG(cond, msg)
 
#define FUZZ_ASSERT(cond)   FUZZ_ASSERT_MSG((cond), "");
 
#define FUZZ_STATIC   static
 
#define FUZZ_rotl32(x, r)   (((x) << (r)) | ((x) >> (32 - (r))))
 

Functions

FUZZ_STATIC uint32_t FUZZ_seed (uint8_t const **src, size_t *size)
 
FUZZ_STATIC uint32_t FUZZ_rand (uint32_t *state)
 
FUZZ_STATIC uint32_t FUZZ_rand32 (uint32_t *state, uint32_t min, uint32_t max)
 

Macro Definition Documentation

◆ FUZZ_ASSERT

#define FUZZ_ASSERT (   cond)    FUZZ_ASSERT_MSG((cond), "");

Definition at line 46 of file fuzz_helpers.h.

◆ FUZZ_ASSERT_MSG

#define FUZZ_ASSERT_MSG (   cond,
  msg 
)
Value:
((cond) ? (void)0 \
: (fprintf(stderr, "%s: %u: Assertion: `%s' failed. %s\n", __FILE__, \
__LINE__, FUZZ_QUOTE(cond), (msg)), \
abort()))
#define FUZZ_QUOTE(str)
Definition: fuzz_helpers.h:36
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define cond(bop, top, mask, flags)

Asserts for fuzzing that are always enabled.

Definition at line 41 of file fuzz_helpers.h.

◆ FUZZ_QUOTE

#define FUZZ_QUOTE (   str)    FUZZ_QUOTE_IMPL(str)

Definition at line 36 of file fuzz_helpers.h.

◆ FUZZ_QUOTE_IMPL

#define FUZZ_QUOTE_IMPL (   str)    #str

Definition at line 35 of file fuzz_helpers.h.

◆ FUZZ_rotl32

#define FUZZ_rotl32 (   x,
  r 
)    (((x) << (r)) | ((x) >> (32 - (r))))

Definition at line 71 of file fuzz_helpers.h.

◆ FUZZ_STATIC

#define FUZZ_STATIC   static

Definition at line 56 of file fuzz_helpers.h.

◆ LZ4_COMMONDEFS_ONLY

#define LZ4_COMMONDEFS_ONLY

Helper functions for fuzzing.

Definition at line 27 of file fuzz_helpers.h.

◆ MAX

#define MAX (   a,
  b 
)    ( (a) > (b) ? (a) : (b) )

Definition at line 33 of file fuzz_helpers.h.

◆ MIN

#define MIN (   a,
  b 
)    ( (a) < (b) ? (a) : (b) )

Definition at line 32 of file fuzz_helpers.h.

Function Documentation

◆ FUZZ_rand()

FUZZ_STATIC uint32_t FUZZ_rand ( uint32_t state)

Definition at line 73 of file fuzz_helpers.h.

73  {
74  static const uint32_t prime1 = 2654435761U;
75  static const uint32_t prime2 = 2246822519U;
76  uint32_t rand32 = *state;
77  rand32 *= prime1;
78  rand32 += prime2;
79  rand32 = FUZZ_rotl32(rand32, 13);
80  *state = rand32;
81  return rand32 >> 5;
82 }
static const U32 prime2
Definition: frametest.c:77
static const U32 prime1
Definition: frametest.c:76
#define FUZZ_rotl32(x, r)
Definition: fuzz_helpers.h:71
unsigned int uint32_t
Definition: sftypes.h:29
Definition: dis.h:43

References FUZZ_rotl32, prime1, and prime2.

Referenced by FUZZ_rand32().

◆ FUZZ_rand32()

FUZZ_STATIC uint32_t FUZZ_rand32 ( uint32_t state,
uint32_t  min,
uint32_t  max 
)

Definition at line 85 of file fuzz_helpers.h.

85  {
86  uint32_t random = FUZZ_rand(state);
87  return min + (random % (max - min + 1));
88 }
int max
Definition: enough.c:225
FUZZ_STATIC uint32_t FUZZ_rand(uint32_t *state)
Definition: fuzz_helpers.h:73
#define min(a, b)
Definition: qsort.h:83

References FUZZ_rand(), max, and min.

Referenced by FUZZ_randomFrameInfo(), FUZZ_randomPreferences(), state_extDictHCRoundTrip(), state_extDictRoundTrip(), state_prefixHCRoundTrip(), state_prefixRoundTrip(), state_randomRoundTrip(), state_reset(), and state_trimDict().

◆ FUZZ_seed()

FUZZ_STATIC uint32_t FUZZ_seed ( uint8_t const **  src,
size_t size 
)

Deterministically constructs a seed based on the fuzz input. Consumes up to the first FUZZ_RNG_SEED_SIZE bytes of the input.

Definition at line 63 of file fuzz_helpers.h.

63  {
64  uint8_t const *data = *src;
65  size_t const toHash = MIN(FUZZ_RNG_SEED_SIZE, *size);
66  *size -= toHash;
67  *src += toHash;
68  return XXH32(data, toHash, 0);
69 }
lzma_index * src
Definition: index.h:567
#define FUZZ_RNG_SEED_SIZE
Definition: fuzz.h:32
#define MIN(a, b)
Definition: fuzz_helpers.h:32
voidpf void uLong size
Definition: ioapi.h:138
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
Definition: xxhash.c:392
unsigned char uint8_t
Definition: sftypes.h:31

References FUZZ_RNG_SEED_SIZE, MIN, src, and XXH32().

Referenced by LLVMFuzzerTestOneInput().