From: Michał Kępień Date: Tue, 30 Oct 2018 12:33:25 +0000 (+0100) Subject: Fix isc_buffer_copyregion() for auto-reallocated buffers X-Git-Tag: v9.13.4~70^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1f0aed03434e9f49208da8c7f617855665d6bca;p=thirdparty%2Fbind9.git Fix isc_buffer_copyregion() for auto-reallocated buffers While isc_buffer_copyregion() calls isc_buffer_reserve() to ensure the target buffer will have enough available space to append the contents of the source region to it, the variables used for subsequently checking available space are not updated accordingly after that call. This prevents isc_buffer_copyregion() from working as expected for auto-reallocated buffers: ISC_R_NOSPACE will be returned if enough space is not already available in the target buffer before it is reallocated. Fix by calling isc_buffer_used() and isc_buffer_availablelength() directly instead of assigning their return values to local variables. --- diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 5eb2620c703..987795be129 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -514,27 +514,24 @@ isc_buffer_dup(isc_mem_t *mctx, isc_buffer_t **dstp, const isc_buffer_t *src) { isc_result_t isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) { - unsigned char *base; - unsigned int available; isc_result_t result; REQUIRE(ISC_BUFFER_VALID(b)); REQUIRE(r != NULL); - /* - * XXXDCL - */ - base = isc_buffer_used(b); - available = isc_buffer_availablelength(b); if (ISC_UNLIKELY(b->autore)) { result = isc_buffer_reserve(&b, r->length); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } - if (r->length > available) + + if (r->length > isc_buffer_availablelength(b)) { return (ISC_R_NOSPACE); + } + if (r->length > 0U) { - memmove(base, r->base, r->length); + memmove(isc_buffer_used(b), r->base, r->length); b->used += r->length; }