diff options
Diffstat (limited to 'src/microhttpd/postprocessor.c')
-rw-r--r-- | src/microhttpd/postprocessor.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c index 1eb33ed6..ecdef5a8 100644 --- a/src/microhttpd/postprocessor.c +++ b/src/microhttpd/postprocessor.c | |||
@@ -353,21 +353,17 @@ MHD_create_post_processor (struct MHD_Connection *connection, | |||
353 | 353 | ||
354 | 354 | ||
355 | /** | 355 | /** |
356 | * Give a (possibly partial) value to the | 356 | * Give a (possibly partial) value to the application callback. We have some |
357 | * application callback. We have some | 357 | * part of the value in the 'pp->xbuf', the rest is between @a value_start and |
358 | * part of the value in the 'pp->xbuf', the | 358 | * @a value_end. If @a last_escape is non-NULL, there may be an incomplete |
359 | * rest is between @a value_start and @a value_end. | 359 | * escape sequence at at @a value_escape between @a value_start and @a |
360 | * If @a last_escape is non-NULL, there may be | 360 | * value_end which we should preserve in 'pp->xbuf' for the future. |
361 | * an incomplete escape sequence at at @a value_escape | ||
362 | * between @a value_start and @a value_end which | ||
363 | * we should preserve in 'pp->xbuf' for the future. | ||
364 | * | 361 | * |
365 | * Unescapes the value and calls the iterator | 362 | * Unescapes the value and calls the iterator together with the key. The key |
366 | * together with the key. The key must already | 363 | * must already be in the key buffer allocated and 0-terminated at the end of |
367 | * be in the key buffer allocated and 0-terminated | 364 | * @a pp at the time of the call. |
368 | * at the end of @a pp at the time of the call. | ||
369 | * | 365 | * |
370 | * @param pp post processor to act upon | 366 | * @param[in,out] pp post processor to act upon |
371 | * @param value_start where in memory is the value | 367 | * @param value_start where in memory is the value |
372 | * @param value_end where does the value end | 368 | * @param value_end where does the value end |
373 | * @param last_escape last '%'-sign in value range, | 369 | * @param last_escape last '%'-sign in value range, |
@@ -404,6 +400,7 @@ process_value (struct MHD_PostProcessor *pp, | |||
404 | (xoff > 0) ) | 400 | (xoff > 0) ) |
405 | { | 401 | { |
406 | size_t delta = value_end - value_start; | 402 | size_t delta = value_end - value_start; |
403 | bool cut = false; | ||
407 | 404 | ||
408 | if (delta > XBUF_SIZE - xoff) | 405 | if (delta > XBUF_SIZE - xoff) |
409 | delta = XBUF_SIZE - xoff; | 406 | delta = XBUF_SIZE - xoff; |
@@ -414,14 +411,23 @@ process_value (struct MHD_PostProcessor *pp, | |||
414 | /* find if escape sequence is at the end of the processing buffer; | 411 | /* find if escape sequence is at the end of the processing buffer; |
415 | if so, exclude those from processing (reduce delta to point at | 412 | if so, exclude those from processing (reduce delta to point at |
416 | end of processed region) */ | 413 | end of processed region) */ |
417 | if (delta >= XBUF_SIZE - 2) | 414 | if ( (xoff + delta > 0) && |
415 | ('%' == xbuf[xoff + delta - 1]) ) | ||
418 | { | 416 | { |
419 | if ((xoff + delta > 0) && | 417 | cut = (delta != XBUF_SIZE - xoff); |
420 | ('%' == xbuf[xoff + delta - 1])) | 418 | delta--; |
421 | delta--; | 419 | pp->xbuf[0] = '%'; |
422 | else if ((xoff + delta > 1) && | 420 | pp->xbuf_pos = 1; |
423 | ('%' == xbuf[xoff + delta - 2])) | 421 | } |
424 | delta -= 2; | 422 | else if ( (xoff + delta > 1) && |
423 | ('%' == xbuf[xoff + delta - 2]) ) | ||
424 | { | ||
425 | memcpy (pp->xbuf, | ||
426 | &xbuf[xoff + delta - 2], | ||
427 | 2); | ||
428 | pp->xbuf_pos = 2; | ||
429 | cut = (delta != XBUF_SIZE - xoff); | ||
430 | delta -= 2; | ||
425 | } | 431 | } |
426 | xoff += delta; | 432 | xoff += delta; |
427 | value_start += delta; | 433 | value_start += delta; |
@@ -447,6 +453,8 @@ process_value (struct MHD_PostProcessor *pp, | |||
447 | } | 453 | } |
448 | pp->value_offset += xoff; | 454 | pp->value_offset += xoff; |
449 | xoff = 0; | 455 | xoff = 0; |
456 | if (cut) | ||
457 | break; | ||
450 | } | 458 | } |
451 | } | 459 | } |
452 | 460 | ||