diff options
Diffstat (limited to 'src/microhttpd/postprocessor.c')
-rw-r--r-- | src/microhttpd/postprocessor.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c index d32ecc22..39070334 100644 --- a/src/microhttpd/postprocessor.c +++ b/src/microhttpd/postprocessor.c | |||
@@ -367,20 +367,23 @@ process_value (struct MHD_PostProcessor *pp, | |||
367 | if ( (NULL != last_escape) && | 367 | if ( (NULL != last_escape) && |
368 | (((size_t) (value_end - last_escape)) < sizeof (pp->xbuf)) ) | 368 | (((size_t) (value_end - last_escape)) < sizeof (pp->xbuf)) ) |
369 | { | 369 | { |
370 | pp->xbuf_pos = value_end - last_escape; | 370 | mhd_assert (value_end >= last_escape); |
371 | pp->xbuf_pos = (size_t) (value_end - last_escape); | ||
371 | memcpy (pp->xbuf, | 372 | memcpy (pp->xbuf, |
372 | last_escape, | 373 | last_escape, |
373 | value_end - last_escape); | 374 | (size_t) (value_end - last_escape)); |
374 | value_end = last_escape; | 375 | value_end = last_escape; |
375 | } | 376 | } |
376 | while ( (value_start != value_end) || | 377 | while ( (value_start != value_end) || |
377 | (pp->must_ikvi) || | 378 | (pp->must_ikvi) || |
378 | (xoff > 0) ) | 379 | (xoff > 0) ) |
379 | { | 380 | { |
380 | size_t delta = value_end - value_start; | 381 | size_t delta = (size_t) (value_end - value_start); |
381 | bool cut = false; | 382 | bool cut = false; |
382 | size_t clen = 0; | 383 | size_t clen = 0; |
383 | 384 | ||
385 | mhd_assert (value_end >= value_start); | ||
386 | |||
384 | if (delta > XBUF_SIZE - xoff) | 387 | if (delta > XBUF_SIZE - xoff) |
385 | delta = XBUF_SIZE - xoff; | 388 | delta = XBUF_SIZE - xoff; |
386 | /* move (additional) input into processing buffer */ | 389 | /* move (additional) input into processing buffer */ |
@@ -660,7 +663,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
660 | mhd_assert ((NULL != end_key) || (NULL == start_key)); | 663 | mhd_assert ((NULL != end_key) || (NULL == start_key)); |
661 | if (1) | 664 | if (1) |
662 | { | 665 | { |
663 | const size_t key_len = end_key - start_key; | 666 | const size_t key_len = (size_t) (end_key - start_key); |
667 | mhd_assert (end_key >= start_key); | ||
664 | if (0 != key_len) | 668 | if (0 != key_len) |
665 | { | 669 | { |
666 | if ( (pp->buffer_pos + key_len >= pp->buffer_size) || | 670 | if ( (pp->buffer_pos + key_len >= pp->buffer_size) || |
@@ -725,7 +729,8 @@ post_process_urlencoded (struct MHD_PostProcessor *pp, | |||
725 | mhd_assert ((PP_ProcessKey == pp->state) || (NULL != end_key)); | 729 | mhd_assert ((PP_ProcessKey == pp->state) || (NULL != end_key)); |
726 | if (NULL == end_key) | 730 | if (NULL == end_key) |
727 | end_key = &post_data[poff]; | 731 | end_key = &post_data[poff]; |
728 | key_len = end_key - start_key; | 732 | mhd_assert (end_key >= start_key); |
733 | key_len = (size_t) (end_key - start_key); | ||
729 | mhd_assert (0 != key_len); /* it must be always non-zero here */ | 734 | mhd_assert (0 != key_len); /* it must be always non-zero here */ |
730 | if (pp->buffer_pos + key_len >= pp->buffer_size) | 735 | if (pp->buffer_pos + key_len >= pp->buffer_size) |
731 | { | 736 | { |
@@ -854,13 +859,13 @@ find_boundary (struct MHD_PostProcessor *pp, | |||
854 | '-', | 859 | '-', |
855 | pp->buffer_pos); | 860 | pp->buffer_pos); |
856 | if (NULL == dash) | 861 | if (NULL == dash) |
857 | (*ioffptr) += pp->buffer_pos; /* skip entire buffer */ | 862 | (*ioffptr) += pp->buffer_pos; /* skip entire buffer */ |
858 | else if (dash == buf) | 863 | else if (dash == buf) |
859 | (*ioffptr)++; /* at least skip one byte */ | 864 | (*ioffptr)++; /* at least skip one byte */ |
860 | else | 865 | else |
861 | (*ioffptr) += dash - buf; /* skip to first possible boundary */ | 866 | (*ioffptr) += (size_t) (dash - buf); /* skip to first possible boundary */ |
862 | } | 867 | } |
863 | return MHD_NO; /* expected boundary */ | 868 | return MHD_NO; /* expected boundary */ |
864 | } | 869 | } |
865 | /* remove boundary from buffer */ | 870 | /* remove boundary from buffer */ |
866 | (*ioffptr) += 2 + blen; | 871 | (*ioffptr) += 2 + blen; |
@@ -908,7 +913,7 @@ try_get_value (const char *buf, | |||
908 | if (NULL == (endv = strchr (&spos[klen + 2], | 913 | if (NULL == (endv = strchr (&spos[klen + 2], |
909 | '\"'))) | 914 | '\"'))) |
910 | return; /* no end-quote */ | 915 | return; /* no end-quote */ |
911 | vlen = endv - spos - klen - 1; | 916 | vlen = (size_t) (endv - spos) - klen - 1; |
912 | *destination = malloc (vlen); | 917 | *destination = malloc (vlen); |
913 | if (NULL == *destination) | 918 | if (NULL == *destination) |
914 | return; /* out of memory */ | 919 | return; /* out of memory */ |
@@ -1037,7 +1042,7 @@ process_value_to_boundary (struct MHD_PostProcessor *pp, | |||
1037 | newline = pp->buffer_pos - 4; | 1042 | newline = pp->buffer_pos - 4; |
1038 | break; | 1043 | break; |
1039 | } | 1044 | } |
1040 | newline = r - buf; | 1045 | newline = (size_t) (r - buf); |
1041 | if (0 == memcmp ("\r\n--", | 1046 | if (0 == memcmp ("\r\n--", |
1042 | &buf[newline], | 1047 | &buf[newline], |
1043 | 4)) | 1048 | 4)) |