]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix isc_buffer_copyregion() for auto-reallocated buffers
authorMichał Kępień <michal@isc.org>
Tue, 30 Oct 2018 12:33:25 +0000 (13:33 +0100)
committerMichał Kępień <michal@isc.org>
Tue, 30 Oct 2018 12:33:25 +0000 (13:33 +0100)
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.

lib/isc/buffer.c

index 5eb2620c703c19acd0f2152e7dda36c8d7bad791..987795be129f80b1ad00caaee0f813df2dff735d 100644 (file)
@@ -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;
        }