44#define FUZZ_HARNESS_NAME "fuzz_postprocessor"
52 256, 257, 300, 512, 1024, 2048, 4096, 65536
56 1, 2, 3, 5, 7, 13, 32, 64, 1024, 0
73 const char *upload_data,
74 size_t *upload_data_size,
77 (void) cls; (void) connection; (void) url; (void) method; (void) version;
78 (void) upload_data; (void) upload_data_size; (void) req_cls;
100 "%s: post processors created=%lu rejected=%lu, "
101 "values reported=%lu\n",
139 const char *filename,
140 const char *content_type,
141 const char *transfer_encoding,
146 struct pp_ctx *ctx = (
struct pp_ctx *) cls;
147 volatile size_t sink = 0;
154 sink += strlen (key);
155 if (
NULL != filename)
156 sink += strlen (filename);
157 if (
NULL != content_type)
158 sink += strlen (content_type);
159 if (
NULL != transfer_encoding)
160 sink += strlen (transfer_encoding);
161 if ( (
NULL !=
data) && (0 != size) )
165 for (i = 0; i < size; i++)
166 sink += (
size_t) (
unsigned char)
data[i];
176 if (off + size > ctx->data_len + 1)
178 "than the POST data contained");
179 if (off > ctx->max_off + ctx->data_len)
223 body = (
char *) malloc (body_len + 1);
226 memcpy (body,
data + 4, body_len);
227 body[body_len] =
'\0';
229 ctype = (
char *) malloc (blen + 64);
251 memcpy (ctype + o,
"; boundary=", 11);
253 for (i = 0; i < blen; i++)
258 ctype[o++] = (
'\0' == ch) ?
'x' : ch;
264 (void) snprintf (ctype, blen + 64,
265 "multipart/form-data; boundary=\"%.*s\"",
266 (
int) ((blen > 40) ? 40 : blen), body);
273 memcpy (ctype,
"text/plain",
sizeof (
"text/plain"));
277 memset (&c, 0,
sizeof (c));
278 memset (&h, 0,
sizeof (h));
290 ctx.data_len = body_len;
304 while (off < body_len)
306 size_t n = (0 == chunk) ? (body_len - off) : chunk;
308 if (n > body_len - off)
329 "Content-Disposition: form-data; name=\"a\"",
330 "Content-Disposition: form-data; name=\"a\"; filename=\"f.txt\"",
331 "Content-Disposition: form-data; name=a",
332 "Content-Disposition: form-data",
333 "Content-Disposition: attachment; name=\"a\"",
334 "Content-Disposition: form-data; name=\"\"",
335 "Content-Disposition: form-data; name=\"a",
336 "Content-Type: text/plain",
337 "Content-Transfer-Encoding: binary",
342 "a=1",
"b=%41",
"c",
"d=",
"=e",
"&",
"&&",
"a=%",
"a=%4",
"a=%zz",
343 "verylongkeyname=verylongvaluewithlotsofcharacters",
"a+b=c+d",
355 const char *boundary;
358 static const char *
const boundaries[] = {
359 "--abc",
"XY",
"boundary",
"-",
"aa",
"0123456789012345678901234567890",
365 const char *s_ = (s); \
366 size_t l_ = strlen (s_); \
367 if (len + l_ >= cap) \
369 memcpy (buf + len, s_, l_); \
377 (uint32_t) (
sizeof (boundaries)
378 /
sizeof (
char *)))];
379 buf[len++] = (uint8_t) (multipart ? (1 +
fuzz_below (rng, 2)) : 0);
382 buf[len++] = (uint8_t) strlen (boundary);
389 for (i = 0; i < nparts; i++)
397 for (k = 0; k <= nhdr; k++)
401 /
sizeof (
char *)))]);
408 for (k = 0; (k < n) && (len < cap); k++)
409 buf[len++] = (uint8_t) (
'A' +
fuzz_below (rng, 26));
420 for (i = 0; i < n; i++)
425 (uint32_t) (
sizeof (
gen_kv) /
sizeof (
char *)))]);
443#define PSEED(t) { t, sizeof (t) - 1 }
446 PSEED (
"\x00\x00\x00\x00" "a=1&b=%41&c"),
447 PSEED (
"\x00\x00\x04\x00" "a=1&b=%41&c"),
448 PSEED (
"\x00\x00\x00\x00" "a=%"),
449 PSEED (
"\x00\x00\x00\x00" "&&&&"),
450 PSEED (
"\x01\x00\x00\x05" "--abc\r\n----abc\r\n"
451 "Content-Disposition: form-data; name=\"k\"\r\n\r\nvalue\r\n"
453 PSEED (
"\x01\x00\x01\x05" "--abc\r\n----abc\r\n"
454 "Content-Disposition: form-data; name=\"k\"; filename=\"f\"\r\n"
455 "Content-Type: text/plain\r\n\r\nvalue\r\n----abc--\r\n"),
456 PSEED (
"\x01\x07\x02\x02" "XY\r\n--XY\r\n\r\nnoheaders\r\n--XY--\r\n"),
457 PSEED (
"\x01\x00\x00\x01" "-\r\n---\r\n\r\nx\r\n-----\r\n"),
458 PSEED (
"\x04\x00\x00\x00" "no boundary at all"),
459 PSEED (
"\x05\x00\x00\x00" "text/plain body"),
460 PSEED (
"\x03\x00\x00\x03" "a\"b\r\n--a\"b\r\n\r\nv\r\n--a\"b--\r\n")
471static const uint8_t *
476 return (
const uint8_t *)
pp_seeds[idx].txt;
Shared, header-only fuzzing driver for the MHD in-process fuzzers.
static FUZZ_UNUSED int fuzz_verbose
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 struct MHD_Daemon * get_shared_daemon(void)
static const size_t chunk_patterns[]
static unsigned long stat_pp_failed
static size_t fuzz_seed_count(void)
static unsigned long stat_pp_created
static const size_t pp_buf_sizes[]
static void stop_shared_daemon(void)
static const char *const gen_kv[]
#define FUZZ_HARNESS_NAME
static const uint8_t * fuzz_seed_get(size_t idx, size_t *len)
static enum MHD_Result post_iter(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static const char *const gen_disp[]
static size_t fuzz_generate(struct fuzz_rng *rng, uint8_t *buf, size_t cap)
static void print_stats(void)
static unsigned long stat_values
static struct MHD_Daemon * shared_daemon
static enum MHD_Result dummy_ahc(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls)
static const struct pp_seed pp_seeds[]
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
#define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA
#define MHD_HTTP_POST_ENCODING_FORM_URLENCODED
_MHD_EXTERN enum MHD_Result MHD_destroy_post_processor(struct MHD_PostProcessor *pp)
_MHD_EXTERN enum MHD_Result MHD_post_process(struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
_MHD_EXTERN struct MHD_PostProcessor * MHD_create_post_processor(struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls)
MHD internal shared structures.
@ MHD_CONNECTION_HEADERS_PROCESSED
#define MHD_STATICSTR_LEN_(macro)
@ MHD_USE_NO_LISTEN_SOCKET
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
struct MHD_HTTP_Req_Header * headers_received
struct MHD_HTTP_Req_Header * headers_received_tail