diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-07-11 19:40:12 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-07-11 19:40:12 +0200 |
commit | 3e50200ee3ad83a965287f63e80dafa3e73a4c50 (patch) | |
tree | 9a7c4874a1eda76a763611917a1f0789c5fb6853 | |
parent | 1899a24a9ff58fb7a50568184b1046f3e0343dd1 (diff) | |
download | libmicrohttpd-3e50200ee3ad83a965287f63e80dafa3e73a4c50.tar.gz libmicrohttpd-3e50200ee3ad83a965287f63e80dafa3e73a4c50.zip |
fixing pp regression
-rw-r--r-- | src/microhttpd/postprocessor.c | 88 |
1 files changed, 58 insertions, 30 deletions
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c index ecdef5a8..43ca1c4b 100644 --- a/src/microhttpd/postprocessor.c +++ b/src/microhttpd/postprocessor.c | |||
@@ -379,6 +379,7 @@ process_value (struct MHD_PostProcessor *pp, | |||
379 | size_t xoff; | 379 | size_t xoff; |
380 | 380 | ||
381 | mhd_assert (pp->xbuf_pos < sizeof (xbuf)); | 381 | mhd_assert (pp->xbuf_pos < sizeof (xbuf)); |
382 | /* move remaining input from previous round into processing buffer */ | ||
382 | memcpy (xbuf, | 383 | memcpy (xbuf, |
383 | pp->xbuf, | 384 | pp->xbuf, |
384 | pp->xbuf_pos); | 385 | pp->xbuf_pos); |
@@ -401,60 +402,87 @@ process_value (struct MHD_PostProcessor *pp, | |||
401 | { | 402 | { |
402 | size_t delta = value_end - value_start; | 403 | size_t delta = value_end - value_start; |
403 | bool cut = false; | 404 | bool cut = false; |
405 | size_t clen = 0; | ||
404 | 406 | ||
405 | if (delta > XBUF_SIZE - xoff) | 407 | if (delta > XBUF_SIZE - xoff) |
406 | delta = XBUF_SIZE - xoff; | 408 | delta = XBUF_SIZE - xoff; |
407 | /* move input into processing buffer */ | 409 | /* move (additional) input into processing buffer */ |
408 | memcpy (&xbuf[xoff], | 410 | memcpy (&xbuf[xoff], |
409 | value_start, | 411 | value_start, |
410 | delta); | 412 | delta); |
413 | xoff += delta; | ||
414 | value_start += delta; | ||
411 | /* find if escape sequence is at the end of the processing buffer; | 415 | /* find if escape sequence is at the end of the processing buffer; |
412 | if so, exclude those from processing (reduce delta to point at | 416 | if so, exclude those from processing (reduce delta to point at |
413 | end of processed region) */ | 417 | end of processed region) */ |
414 | if ( (xoff + delta > 0) && | 418 | if ( (xoff > 0) && |
415 | ('%' == xbuf[xoff + delta - 1]) ) | 419 | ('%' == xbuf[xoff - 1]) ) |
416 | { | 420 | { |
417 | cut = (delta != XBUF_SIZE - xoff); | 421 | cut = (xoff != XBUF_SIZE); |
418 | delta--; | 422 | xoff--; |
419 | pp->xbuf[0] = '%'; | 423 | if (cut) |
420 | pp->xbuf_pos = 1; | 424 | { |
425 | /* move escape sequence into buffer for next function invocation */ | ||
426 | pp->xbuf[0] = '%'; | ||
427 | pp->xbuf_pos = 1; | ||
428 | } | ||
429 | else | ||
430 | { | ||
431 | /* just skip escape sequence for next loop iteration */ | ||
432 | delta = xoff; | ||
433 | clen = 1; | ||
434 | } | ||
421 | } | 435 | } |
422 | else if ( (xoff + delta > 1) && | 436 | else if ( (xoff > 1) && |
423 | ('%' == xbuf[xoff + delta - 2]) ) | 437 | ('%' == xbuf[xoff - 2]) ) |
424 | { | 438 | { |
425 | memcpy (pp->xbuf, | 439 | cut = (xoff != XBUF_SIZE); |
426 | &xbuf[xoff + delta - 2], | 440 | xoff -= 2; |
427 | 2); | 441 | if (cut) |
428 | pp->xbuf_pos = 2; | 442 | { |
429 | cut = (delta != XBUF_SIZE - xoff); | 443 | /* move escape sequence into buffer for next function invocation */ |
430 | delta -= 2; | 444 | memcpy (pp->xbuf, |
445 | &xbuf[xoff], | ||
446 | 2); | ||
447 | pp->xbuf_pos = 2; | ||
448 | } | ||
449 | else | ||
450 | { | ||
451 | /* just skip escape sequence for next loop iteration */ | ||
452 | delta = xoff; | ||
453 | clen = 2; | ||
454 | } | ||
431 | } | 455 | } |
432 | xoff += delta; | ||
433 | value_start += delta; | ||
434 | mhd_assert (xoff < sizeof (xbuf)); | 456 | mhd_assert (xoff < sizeof (xbuf)); |
435 | /* unescape */ | 457 | /* unescape */ |
436 | xbuf[xoff] = '\0'; /* 0-terminate in preparation */ | 458 | xbuf[xoff] = '\0'; /* 0-terminate in preparation */ |
437 | MHD_unescape_plus (xbuf); | 459 | MHD_unescape_plus (xbuf); |
438 | xoff = MHD_http_unescape (xbuf); | 460 | xoff = MHD_http_unescape (xbuf); |
439 | /* finally: call application! */ | 461 | /* finally: call application! */ |
440 | pp->must_ikvi = false; | 462 | if ( (pp->must_ikvi || (0 != xoff)) ) |
441 | if (MHD_NO == pp->ikvi (pp->cls, | ||
442 | MHD_POSTDATA_KIND, | ||
443 | (const char *) &pp[1], /* key */ | ||
444 | NULL, | ||
445 | NULL, | ||
446 | NULL, | ||
447 | xbuf, | ||
448 | pp->value_offset, | ||
449 | xoff)) | ||
450 | { | 463 | { |
451 | pp->state = PP_Error; | 464 | pp->must_ikvi = false; |
452 | return; | 465 | if (MHD_NO == pp->ikvi (pp->cls, |
466 | MHD_POSTDATA_KIND, | ||
467 | (const char *) &pp[1], /* key */ | ||
468 | NULL, | ||
469 | NULL, | ||
470 | NULL, | ||
471 | xbuf, | ||
472 | pp->value_offset, | ||
473 | xoff)) | ||
474 | { | ||
475 | pp->state = PP_Error; | ||
476 | return; | ||
477 | } | ||
453 | } | 478 | } |
454 | pp->value_offset += xoff; | 479 | pp->value_offset += xoff; |
455 | xoff = 0; | ||
456 | if (cut) | 480 | if (cut) |
457 | break; | 481 | break; |
482 | memmove (xbuf, | ||
483 | &xbuf[delta], | ||
484 | clen); | ||
485 | xoff = clen; | ||
458 | } | 486 | } |
459 | } | 487 | } |
460 | 488 | ||