43#define FUZZ_HARNESS_NAME "fuzz_str"
53#define MODEL_MAX_DIGEST 32
98 void *p = malloc ((0 == n) ? 1 : n);
110 char *p = (
char *)
xalloc (n + 1);
144 size_t need = (n / 2) + (n % 2);
145 uint8_t *out = (uint8_t *)
xalloc (need);
150 "than its documented output size");
157 char *out = (
char *)
xalloc (2 * n);
168 char *out = (
char *)
xalloc (2 * n + 1);
184 char *out = (
char *)
xalloc (n);
190 "documented output size");
192 small = (0 == n) ? 0 : (n * (aux % 100u)) / 100u;
193 out = (
char *)
xalloc (small);
201 char *out = (
char *)
xalloc (n);
209 "documented output size");
211 small = (0 == n) ? 0 : (n * (aux % 100u)) / 100u;
212 out = (
char *)
xalloc (small);
221 char *s =
dup_z (p, n);
233 char *s =
dup_z (p, n);
248 char *out = (
char *)
xalloc (n);
249 size_t r = MHD_str_unquote ((
const char *) p, n, out);
253 "the quoted input had");
262#if defined(DAUTH_SUPPORT) || defined(BAUTH_SUPPORT)
266 char *out = (
char *)
xalloc (2 * n);
267 size_t r = MHD_str_quote ((
const char *) p, n, out, 2 * n);
273 small = (0 == n) ? 0 : (n * (aux % 200u)) / 100u;
274 out = (
char *)
xalloc (small);
275 (void) MHD_str_quote ((
const char *) p, n, out, small);
287 size_t need = MHD_base64_max_dec_size_ (n);
288 uint8_t *out = (uint8_t *)
xalloc (need);
289 size_t r = MHD_base64_to_bin_n ((
const char *) p, n, out, need);
294 "MHD_base64_max_dec_size_()");
296 small = (0 == need) ? 0 : (need * (aux % 100u)) / 100u;
297 out = (uint8_t *)
xalloc (small);
298 (void) MHD_base64_to_bin_n ((
const char *) p, n, out, small);
309 char *s =
dup_z (p, n);
317 "maxlen characters");
320 "maxlen characters");
330 char *s =
dup_z (p, n);
331 size_t split = (0 == n) ? 0 : (aux % n);
332 char *tok =
dup_z (p + split, n - split);
338 for (k = 0; k < n - split; k++)
340 if ( (
'\0' == tok[k]) || (
' ' == tok[k]) ||
341 (
'\t' == tok[k]) || (
',' == tok[k]) )
348 tok =
dup_z ((
const uint8_t *)
"chunked", 7);
354 bs = (ssize_t) (n + n / 2 + 1);
355 out = (
char *)
xalloc ((
size_t) bs);
357 if (bs > (ssize_t) (n + n / 2 + 1))
359 "result larger than the documented 50% growth");
364 char *norm =
dup_z ((
const uint8_t *) out, (
size_t) bs);
365 size_t nlen = (size_t) bs;
368 if (nlen > (
size_t) bs)
381 size_t split = (0 == n) ? 0 : (aux % n);
382 char *a =
dup_z (p, split);
383 char *b =
dup_z (p + split, n - split);
386 ? split : (n - split));
401 const char *e = getenv (
"MHD_FUZZ_MODEL_DIGEST_SINK");
432 "%41",
"%",
"%%",
"%zz",
"%0",
"%00",
"%ff",
"\\",
"\\\"",
"\"",
433 "0123456789abcdef",
"0123456789ABCDEF",
"ffffffffffffffffffffffff",
434 "gg",
"0x",
"18446744073709551615",
"99999999999999999999",
435 "a, b, c",
"chunked",
"identity",
" , ",
",,",
"token",
436 "QUJD",
"QQ==",
"Q===",
"====",
"AAAA",
"AA=A",
437 "\x00\x01\x7f\x80\xff",
" ",
"\t",
"\r\n"
455 for (i = 0; i < natoms; i++)
464 for (k = 0; (k < run) && (len < cap); k++)
465 buf[len++] = (uint8_t)
"0123456789abcdef"[
fuzz_below (rng, 16)];
477 /
sizeof (
char *)))];
478 size_t al = strlen (a);
482 memcpy (buf + len, a, al);
500#define SSEED(t) { t, sizeof (t) - 1 }
506 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
507 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"),
508 SSEED (
"\x00\x00" "0123456789abcdef0123456789abcdef"),
509 SSEED (
"\x00\x00" "abc"),
510 SSEED (
"\x00\x00" "zz"),
511 SSEED (
"\x01\x00" "\x01\x02\x03\x04"),
512 SSEED (
"\x02\x00" "\xff\xfe"),
513 SSEED (
"\x03\x00" "/a%41%42%zz%"),
514 SSEED (
"\x04\x40" "/a%41%42%zz%"),
515 SSEED (
"\x05\x00" "%41%42%%%0"),
516 SSEED (
"\x06\x00" "%41%42%%%0"),
517 SSEED (
"\x07\x00" "a\\\"b\\\\c"),
518 SSEED (
"\x08\x00" "a\"b\\c"),
519 SSEED (
"\x09\x00" "QUJDRA=="),
520 SSEED (
"\x09\x00" "QUJDR==="),
521 SSEED (
"\x0a\x00" "18446744073709551615"),
522 SSEED (
"\x0a\x00" "ffffffffffffffff"),
523 SSEED (
"\x0b\x03" "chunked, identity, chunked"),
524 SSEED (
"\x0c\x04" "CHUNKEDchunked"),
526 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
527 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
538static const uint8_t *
543 return (
const uint8_t *)
str_seeds[idx].txt;
Shared, header-only fuzzing driver for the MHD in-process fuzzers.
static FUZZ_UNUSED uint32_t fuzz_below(struct fuzz_rng *r, uint32_t n)
static FUZZ_UNUSED uint8_t fuzz_byte(struct fuzz_rng *r)
static FUZZ_UNUSED void fuzz_report_finding(const char *what)
static FUZZ_UNUSED int fuzz_chance(struct fuzz_rng *r, uint32_t n)
static size_t fuzz_seed_count(void)
static const char *const gen_str_atoms[]
static int model_digest_sink_read
static const uint8_t * fuzz_seed_get(size_t idx, size_t *len)
static int model_digest_sink
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static void * xalloc(size_t n)
static size_t fuzz_generate(struct fuzz_rng *rng, uint8_t *buf, size_t cap)
static const struct str_seed str_seeds[]
@ TGT_PCT_IN_PLACE_LENIENT
@ TGT_PCT_IN_PLACE_STRICT
static char * dup_z(const uint8_t *d, size_t n)
additional automatic macros for MHD_config.h
size_t MHD_bin_to_hex(const void *bin, size_t size, char *hex)
size_t MHD_str_pct_decode_strict_n_(const char *pct_encoded, size_t pct_encoded_len, char *decoded, size_t buf_size)
size_t MHD_bin_to_hex_z(const void *bin, size_t size, char *hex)
bool MHD_str_remove_tokens_caseless_(char *str, size_t *str_len, const char *const tokens, const size_t tokens_len)
size_t MHD_str_pct_decode_lenient_n_(const char *pct_encoded, size_t pct_encoded_len, char *decoded, size_t buf_size, bool *broken_encoding)
size_t MHD_str_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
size_t MHD_str_pct_decode_in_place_lenient_(char *str, bool *broken_encoding)
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
int MHD_str_equal_caseless_n_(const char *const str1, const char *const str2, size_t maxlen)
size_t MHD_str_pct_decode_in_place_strict_(char *str)
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
bool MHD_str_remove_token_caseless_(const char *str, size_t str_len, const char *const token, const size_t token_len, char *buf, ssize_t *buf_size)
bool MHD_str_equal_caseless_bin_n_(const char *const str1, const char *const str2, size_t len)
size_t MHD_hex_to_bin(const char *hex, size_t len, void *bin)
Header for string manipulating helpers.