2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

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.
This commit is contained in:
Michał Kępień
2018-10-30 13:33:25 +01:00
parent 15440d8027
commit e1f0aed034

View 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;
}