aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_postprocessor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_postprocessor.c')
-rw-r--r--src/microhttpd/test_postprocessor.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index e70171cc..b62e7ff9 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -451,6 +451,71 @@ test_empty_value (void)
451} 451}
452 452
453 453
454static enum MHD_Result
455value_checker2 (void *cls,
456 enum MHD_ValueKind kind,
457 const char *key,
458 const char *filename,
459 const char *content_type,
460 const char *transfer_encoding,
461 const char *data,
462 uint64_t off,
463 size_t size)
464{
465 return MHD_YES;
466}
467
468
469static int
470test_overflow ()
471{
472 struct MHD_Connection connection;
473 struct MHD_HTTP_Header header;
474 struct MHD_PostProcessor *pp;
475 size_t i;
476 size_t j;
477 size_t delta;
478 char *buf;
479
480 memset (&connection, 0, sizeof (struct MHD_Connection));
481 memset (&header, 0, sizeof (struct MHD_HTTP_Header));
482 connection.headers_received = &header;
483 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
484 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
485 header.header_size = strlen (header.header);
486 header.value_size = strlen (header.value);
487 header.kind = MHD_HEADER_KIND;
488 for (i = 128; i < 1024 * 1024; i += 1024)
489 {
490 pp = MHD_create_post_processor (&connection,
491 1024,
492 &value_checker2,
493 NULL);
494 buf = malloc (i);
495 if (NULL == buf)
496 return 1;
497 memset (buf, 'A', i);
498 buf[i / 2] = '=';
499 delta = 1 + (MHD_random_ () % (i - 1));
500 j = 0;
501 while (j < i)
502 {
503 if (j + delta > i)
504 delta = i - j;
505 if (MHD_NO ==
506 MHD_post_process (pp,
507 &buf[j],
508 delta))
509 break;
510 j += delta;
511 }
512 free (buf);
513 MHD_destroy_post_processor (pp);
514 }
515 return 0;
516}
517
518
454int 519int
455main (int argc, char *const *argv) 520main (int argc, char *const *argv)
456{ 521{
@@ -463,6 +528,7 @@ main (int argc, char *const *argv)
463 errorCount += test_multipart (); 528 errorCount += test_multipart ();
464 errorCount += test_nested_multipart (); 529 errorCount += test_nested_multipart ();
465 errorCount += test_empty_value (); 530 errorCount += test_empty_value ();
531 errorCount += test_overflow ();
466 if (errorCount != 0) 532 if (errorCount != 0)
467 fprintf (stderr, "Error (code: %u)\n", errorCount); 533 fprintf (stderr, "Error (code: %u)\n", errorCount);
468 return errorCount != 0; /* 0 == pass */ 534 return errorCount != 0; /* 0 == pass */