|
GNU libmicrohttpd 1.0.9
|
Direct in-process fuzzer for the string primitives of mhd_str.c. More...

Go to the source code of this file.
Macros | |
| #define | FUZZ_HARNESS_NAME "fuzz_str" |
| #define | MODEL_MAX_DIGEST 32 |
| #define | SSEED(t) |
Enumerations | |
| enum | str_target { TGT_HEX_TO_BIN = 0 , TGT_BIN_TO_HEX , TGT_BIN_TO_HEX_Z , TGT_PCT_STRICT , TGT_PCT_LENIENT , TGT_PCT_IN_PLACE_STRICT , TGT_PCT_IN_PLACE_LENIENT , TGT_UNQUOTE , TGT_QUOTE , TGT_BASE64 , TGT_TO_UINT64 , TGT_TOKENS , TGT_EQUAL_CASELESS , TGT_DIGEST_HEX_SINK , TGT_COUNT } |
Functions | |
| static void * | xalloc (size_t n) |
| static char * | dup_z (const uint8_t *d, size_t n) |
| int | LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) |
| static size_t | fuzz_generate (struct fuzz_rng *rng, uint8_t *buf, size_t cap) |
| static size_t | fuzz_seed_count (void) |
| static const uint8_t * | fuzz_seed_get (size_t idx, size_t *len) |
Variables | |
| static int | model_digest_sink |
| static int | model_digest_sink_read |
| static const char *const | gen_str_atoms [] |
| static const struct str_seed | str_seeds [] |
Direct in-process fuzzer for the string primitives of mhd_str.c.
Every destination buffer is obtained with malloc() at exactly the size that the documented contract of the function under test requires – never a generous stack array. Under AddressSanitizer the redzone immediately after the allocation turns any one-byte over-write into a hard error, which is precisely the property a fixed-size stack buffer would not give us.
In addition to the contract-exact calls, several functions are also called with a deliberately too small output buffer: functions that take a buffer size argument must detect this and must not write past the end.
Input format: byte 0 target selector byte 1 auxiliary parameter (buffer size shrink, split point, ...) byte 2.. payload
Definition in file fuzz_str.c.
| #define FUZZ_HARNESS_NAME "fuzz_str" |
Definition at line 43 of file fuzz_str.c.
| #define MODEL_MAX_DIGEST 32 |
Largest digest MHD supports; this is the size of the on-stack buffers that digestauth.c passes to MHD_hex_to_bin().
Definition at line 53 of file fuzz_str.c.
Referenced by LLVMFuzzerTestOneInput().
| #define SSEED | ( | t | ) |
Definition at line 500 of file fuzz_str.c.
| enum str_target |
Definition at line 70 of file fuzz_str.c.
|
static |
Definition at line 107 of file fuzz_str.c.
References xalloc().
Referenced by LLVMFuzzerTestOneInput().


|
static |
Definition at line 442 of file fuzz_str.c.
References fuzz_below(), fuzz_byte(), fuzz_chance(), gen_str_atoms, and TGT_COUNT.

|
static |
Definition at line 532 of file fuzz_str.c.
References str_seeds.
|
static |
Definition at line 539 of file fuzz_str.c.
References str_seeds.
| int LLVMFuzzerTestOneInput | ( | const uint8_t * | data, |
| size_t | size ) |
The fuzz target. Signature is the libFuzzer one on purpose, so that the very same harness can be linked with libFuzzer or AFL++ later.
< see queue_unprocessed_conn()
Definition at line 119 of file fuzz_str.c.
References data, dup_z(), fuzz_report_finding(), MHD_bin_to_hex(), MHD_bin_to_hex_z(), MHD_hex_to_bin(), MHD_str_equal_caseless_bin_n_(), MHD_str_equal_caseless_n_(), MHD_str_has_token_caseless_(), MHD_str_pct_decode_in_place_lenient_(), MHD_str_pct_decode_in_place_strict_(), MHD_str_pct_decode_lenient_n_(), MHD_str_pct_decode_strict_n_(), MHD_str_remove_token_caseless_(), MHD_str_remove_tokens_caseless_(), MHD_str_to_uint64_n_(), MHD_strx_to_uint64_n_(), model_digest_sink, model_digest_sink_read, MODEL_MAX_DIGEST, NULL, TGT_BASE64, TGT_BIN_TO_HEX, TGT_BIN_TO_HEX_Z, TGT_COUNT, TGT_DIGEST_HEX_SINK, TGT_EQUAL_CASELESS, TGT_HEX_TO_BIN, TGT_PCT_IN_PLACE_LENIENT, TGT_PCT_IN_PLACE_STRICT, TGT_PCT_LENIENT, TGT_PCT_STRICT, TGT_QUOTE, TGT_TO_UINT64, TGT_TOKENS, TGT_UNQUOTE, and xalloc().

|
static |
Allocate exactly n bytes. Zero-sized allocations are turned into a one byte allocation so that the returned pointer stays valid, but the harness never tells the library about that extra byte.
Definition at line 96 of file fuzz_str.c.
References NULL.
Referenced by dup_z(), and LLVMFuzzerTestOneInput().

|
static |
Definition at line 431 of file fuzz_str.c.
Referenced by fuzz_generate().
|
static |
Model the (pre-2026) digestauth.c call site that fed a client controlled, up to 4 * digest_size characters long 'response' value into MHD_hex_to_bin() together with a digest_size byte buffer.
MHD_hex_to_bin() has no output size parameter: it writes len/2 bytes, so a caller with a fixed size buffer must bound the input length. This target replays that call site with an exactly sized heap buffer so that ASAN reports the overflow. It is OFF by default (it models a caller, not the library) – enable it with MHD_FUZZ_MODEL_DIGEST_SINK=1 to reproduce the primitive behind the digest 'response' overflow.
Definition at line 67 of file fuzz_str.c.
Referenced by LLVMFuzzerTestOneInput().
|
static |
Definition at line 68 of file fuzz_str.c.
Referenced by LLVMFuzzerTestOneInput().
|
static |
Definition at line 502 of file fuzz_str.c.
Referenced by fuzz_seed_count(), and fuzz_seed_get().