mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 08:05:21 +00:00
Enable auto-reallocation for all isc_buffer_allocate() buffers
When isc_buffer_t buffer is created with isc_buffer_allocate() assume that we want it to always auto-reallocate instead of having an extra call to enable auto-reallocation.
This commit is contained in:
@@ -1548,7 +1548,6 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
isc_buffer_allocate(zone->catzs->mctx, &aclb, 16);
|
isc_buffer_allocate(zone->catzs->mctx, &aclb, 16);
|
||||||
isc_buffer_setautorealloc(aclb, true);
|
|
||||||
for (result = dns_rdata_apl_first(&rdata_apl); result == ISC_R_SUCCESS;
|
for (result = dns_rdata_apl_first(&rdata_apl); result == ISC_R_SUCCESS;
|
||||||
result = dns_rdata_apl_next(&rdata_apl))
|
result = dns_rdata_apl_next(&rdata_apl))
|
||||||
{
|
{
|
||||||
@@ -1940,7 +1939,6 @@ dns_catz_generate_zonecfg(dns_catz_zone_t *zone, dns_catz_entry_t *entry,
|
|||||||
*/
|
*/
|
||||||
isc_buffer_allocate(zone->catzs->mctx, &buffer, ISC_BUFFER_INCR);
|
isc_buffer_allocate(zone->catzs->mctx, &buffer, ISC_BUFFER_INCR);
|
||||||
|
|
||||||
isc_buffer_setautorealloc(buffer, true);
|
|
||||||
isc_buffer_putstr(buffer, "zone \"");
|
isc_buffer_putstr(buffer, "zone \"");
|
||||||
dns_name_totext(&entry->name, true, buffer);
|
dns_name_totext(&entry->name, true, buffer);
|
||||||
isc_buffer_putstr(buffer, "\" { type secondary; primaries");
|
isc_buffer_putstr(buffer, "\" { type secondary; primaries");
|
||||||
|
@@ -36,7 +36,7 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) {
|
|||||||
*/
|
*/
|
||||||
REQUIRE(b->length <= length);
|
REQUIRE(b->length <= length);
|
||||||
REQUIRE(base != NULL);
|
REQUIRE(base != NULL);
|
||||||
REQUIRE(!b->autore);
|
REQUIRE(b->mctx == NULL);
|
||||||
|
|
||||||
if (b->length > 0U) {
|
if (b->length > 0U) {
|
||||||
(void)memmove(base, b->base, b->length);
|
(void)memmove(base, b->base, b->length);
|
||||||
@@ -46,13 +46,6 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) {
|
|||||||
b->length = length;
|
b->length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
isc_buffer_setautorealloc(isc_buffer_t *b, bool enable) {
|
|
||||||
REQUIRE(ISC_BUFFER_VALID(b));
|
|
||||||
REQUIRE(b->mctx != NULL);
|
|
||||||
b->autore = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_buffer_compact(isc_buffer_t *b) {
|
isc_buffer_compact(isc_buffer_t *b) {
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
@@ -107,7 +100,7 @@ isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r) {
|
|||||||
REQUIRE(ISC_BUFFER_VALID(b));
|
REQUIRE(ISC_BUFFER_VALID(b));
|
||||||
REQUIRE(r != NULL);
|
REQUIRE(r != NULL);
|
||||||
|
|
||||||
if (b->autore) {
|
if (b->mctx) {
|
||||||
result = isc_buffer_reserve(b, r->length);
|
result = isc_buffer_reserve(b, r->length);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
return (result);
|
return (result);
|
||||||
@@ -136,8 +129,6 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
|||||||
|
|
||||||
isc_buffer_init(dbuf, bdata, length);
|
isc_buffer_init(dbuf, bdata, length);
|
||||||
|
|
||||||
ENSURE(ISC_BUFFER_VALID(dbuf));
|
|
||||||
|
|
||||||
dbuf->mctx = mctx;
|
dbuf->mctx = mctx;
|
||||||
|
|
||||||
*dynbuffer = dbuf;
|
*dynbuffer = dbuf;
|
||||||
@@ -213,7 +204,7 @@ isc_buffer_printf(isc_buffer_t *b, const char *format, ...) {
|
|||||||
return (ISC_R_FAILURE);
|
return (ISC_R_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->autore) {
|
if (b->mctx) {
|
||||||
result = isc_buffer_reserve(b, n + 1);
|
result = isc_buffer_reserve(b, n + 1);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
return (result);
|
return (result);
|
||||||
|
@@ -562,7 +562,6 @@ isc__httpd_sendreq_new(isc_httpd_t *httpd) {
|
|||||||
*/
|
*/
|
||||||
isc_buffer_allocate(req->mctx, &req->sendbuffer, HTTP_SENDLEN);
|
isc_buffer_allocate(req->mctx, &req->sendbuffer, HTTP_SENDLEN);
|
||||||
isc_buffer_clear(req->sendbuffer);
|
isc_buffer_clear(req->sendbuffer);
|
||||||
isc_buffer_setautorealloc(req->sendbuffer, true);
|
|
||||||
|
|
||||||
isc_buffer_initnull(&req->bodybuffer);
|
isc_buffer_initnull(&req->bodybuffer);
|
||||||
|
|
||||||
|
@@ -182,8 +182,6 @@ struct isc_buffer {
|
|||||||
ISC_LINK(isc_buffer_t) link;
|
ISC_LINK(isc_buffer_t) link;
|
||||||
/*! private internal elements */
|
/*! private internal elements */
|
||||||
isc_mem_t *mctx;
|
isc_mem_t *mctx;
|
||||||
/* automatically realloc buffer at put* */
|
|
||||||
bool autore;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -253,16 +251,6 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length);
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
|
||||||
isc_buffer_setautorealloc(isc_buffer_t *b, bool enable);
|
|
||||||
/*!<
|
|
||||||
* \brief Enable or disable autoreallocation on 'b'.
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
*\li 'b' is a valid dynamic buffer (b->mctx != NULL).
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_buffer_compact(isc_buffer_t *b);
|
isc_buffer_compact(isc_buffer_t *b);
|
||||||
/*!<
|
/*!<
|
||||||
@@ -854,7 +842,7 @@ isc_buffer_getuint8(isc_buffer_t *b) {
|
|||||||
{ \
|
{ \
|
||||||
REQUIRE(ISC_BUFFER_VALID(b)); \
|
REQUIRE(ISC_BUFFER_VALID(b)); \
|
||||||
\
|
\
|
||||||
if (b->autore) { \
|
if (b->mctx) { \
|
||||||
isc_result_t result = isc_buffer_reserve(b, \
|
isc_result_t result = isc_buffer_reserve(b, \
|
||||||
sizeof(val)); \
|
sizeof(val)); \
|
||||||
ENSURE(result == ISC_R_SUCCESS); \
|
ENSURE(result == ISC_R_SUCCESS); \
|
||||||
@@ -969,7 +957,7 @@ isc_buffer_putmem(isc_buffer_t *b, const unsigned char *base,
|
|||||||
unsigned int length) {
|
unsigned int length) {
|
||||||
ISC_REQUIRE(ISC_BUFFER_VALID(b));
|
ISC_REQUIRE(ISC_BUFFER_VALID(b));
|
||||||
|
|
||||||
if (b->autore) {
|
if (b->mctx) {
|
||||||
isc_result_t result = isc_buffer_reserve(b, length);
|
isc_result_t result = isc_buffer_reserve(b, length);
|
||||||
ISC_REQUIRE(result == ISC_R_SUCCESS);
|
ISC_REQUIRE(result == ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
@@ -1005,7 +993,7 @@ isc_buffer_putstr(isc_buffer_t *b, const char *source) {
|
|||||||
ISC_REQUIRE(source != NULL);
|
ISC_REQUIRE(source != NULL);
|
||||||
|
|
||||||
length = (unsigned int)strlen(source);
|
length = (unsigned int)strlen(source);
|
||||||
if (b->autore) {
|
if (b->mctx) {
|
||||||
isc_result_t result = isc_buffer_reserve(b, length);
|
isc_result_t result = isc_buffer_reserve(b, length);
|
||||||
ISC_ENSURE(result == ISC_R_SUCCESS);
|
ISC_ENSURE(result == ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@@ -443,7 +443,6 @@ new_http_cstream(isc_nmsocket_t *sock, http_cstream_t **streamp) {
|
|||||||
|
|
||||||
isc_buffer_allocate(mctx, &stream->rbuf,
|
isc_buffer_allocate(mctx, &stream->rbuf,
|
||||||
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
|
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
|
||||||
isc_buffer_setautorealloc(stream->rbuf, true);
|
|
||||||
|
|
||||||
ISC_LIST_PREPEND(sock->h2.session->cstreams, stream, link);
|
ISC_LIST_PREPEND(sock->h2.session->cstreams, stream, link);
|
||||||
*streamp = stream;
|
*streamp = stream;
|
||||||
@@ -1005,7 +1004,6 @@ http_readcb(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
|
|||||||
if (session->buf == NULL) {
|
if (session->buf == NULL) {
|
||||||
isc_buffer_allocate(session->mctx, &session->buf,
|
isc_buffer_allocate(session->mctx, &session->buf,
|
||||||
unread_size);
|
unread_size);
|
||||||
isc_buffer_setautorealloc(session->buf, true);
|
|
||||||
}
|
}
|
||||||
isc_buffer_putmem(session->buf, region->base + readlen,
|
isc_buffer_putmem(session->buf, region->base + readlen,
|
||||||
unread_size);
|
unread_size);
|
||||||
@@ -1121,8 +1119,6 @@ http_send_outgoing(isc_nm_http_session_t *session, isc_nmhandle_t *httphandle,
|
|||||||
isc_buffer_allocate(session->mctx,
|
isc_buffer_allocate(session->mctx,
|
||||||
&session->pending_write_data,
|
&session->pending_write_data,
|
||||||
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
|
INITIAL_DNS_MESSAGE_BUFFER_SIZE);
|
||||||
isc_buffer_setautorealloc(session->pending_write_data,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
isc_buffer_putmem(session->pending_write_data, data, pending);
|
isc_buffer_putmem(session->pending_write_data, data, pending);
|
||||||
total = new_total;
|
total = new_total;
|
||||||
@@ -1267,13 +1263,15 @@ http_do_bio(isc_nm_http_session_t *session, isc_nmhandle_t *send_httphandle,
|
|||||||
|
|
||||||
if (nghttp2_session_want_read(session->ngsession) != 0) {
|
if (nghttp2_session_want_read(session->ngsession) != 0) {
|
||||||
if (!session->reading) {
|
if (!session->reading) {
|
||||||
/* We have not yet started reading from this handle */
|
/* We have not yet started
|
||||||
|
* reading from this handle */
|
||||||
isc_nm_read(session->handle, http_readcb, session);
|
isc_nm_read(session->handle, http_readcb, session);
|
||||||
session->reading = true;
|
session->reading = true;
|
||||||
} else if (session->buf != NULL) {
|
} else if (session->buf != NULL) {
|
||||||
size_t remaining =
|
size_t remaining =
|
||||||
isc_buffer_remaininglength(session->buf);
|
isc_buffer_remaininglength(session->buf);
|
||||||
/* Leftover data in the buffer, use it */
|
/* Leftover data in the
|
||||||
|
* buffer, use it */
|
||||||
size_t readlen = nghttp2_session_mem_recv(
|
size_t readlen = nghttp2_session_mem_recv(
|
||||||
session->ngsession,
|
session->ngsession,
|
||||||
isc_buffer_current(session->buf), remaining);
|
isc_buffer_current(session->buf), remaining);
|
||||||
@@ -1288,7 +1286,9 @@ http_do_bio(isc_nm_http_session_t *session, isc_nmhandle_t *send_httphandle,
|
|||||||
send_cbarg);
|
send_cbarg);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
/* Resume reading, it's idempotent, wait for more */
|
/* Resume reading, it's
|
||||||
|
* idempotent, wait for more
|
||||||
|
*/
|
||||||
isc_nm_read(session->handle, http_readcb, session);
|
isc_nm_read(session->handle, http_readcb, session);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1406,9 +1406,10 @@ transport_connect_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
|
|||||||
NGHTTP2_PROTO_VERSION_ID_LEN) != 0)
|
NGHTTP2_PROTO_VERSION_ID_LEN) != 0)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* HTTP/2 negotiation error. Any sensible DoH
|
* HTTP/2 negotiation error.
|
||||||
* client will fail if HTTP/2 cannot be
|
* Any sensible DoH client
|
||||||
* negotiated via ALPN.
|
* will fail if HTTP/2 cannot
|
||||||
|
* be negotiated via ALPN.
|
||||||
*/
|
*/
|
||||||
result = ISC_R_HTTP2ALPNERROR;
|
result = ISC_R_HTTP2ALPNERROR;
|
||||||
goto error;
|
goto error;
|
||||||
@@ -2346,9 +2347,12 @@ server_on_frame_recv_callback(nghttp2_session *ngsession,
|
|||||||
ngsession, frame->hd.stream_id);
|
ngsession, frame->hd.stream_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For DATA and HEADERS frame, this callback may be
|
* For DATA and HEADERS frame,
|
||||||
* called after on_stream_close_callback. Check that
|
* this callback may be called
|
||||||
* the stream is still alive.
|
* after
|
||||||
|
* on_stream_close_callback.
|
||||||
|
* Check that the stream is
|
||||||
|
* still alive.
|
||||||
*/
|
*/
|
||||||
if (socket == NULL) {
|
if (socket == NULL) {
|
||||||
return (0);
|
return (0);
|
||||||
@@ -3168,9 +3172,12 @@ isc__nm_base64_to_base64url(isc_mem_t *mem, const char *base64,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
* All other characters from the alphabet are the same
|
* All other characters from
|
||||||
* for both base64 and base64url, so we can reuse the
|
* the alphabet are the same
|
||||||
* validation table for the rest of the characters.
|
* for both base64 and
|
||||||
|
* base64url, so we can reuse
|
||||||
|
* the validation table for
|
||||||
|
* the rest of the characters.
|
||||||
*/
|
*/
|
||||||
if (base64[i] != '-' && base64[i] != '_' &&
|
if (base64[i] != '-' && base64[i] != '_' &&
|
||||||
base64url_validation_table[(size_t)base64[i]])
|
base64url_validation_table[(size_t)base64[i]])
|
||||||
|
@@ -113,8 +113,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_dynamic) {
|
|||||||
assert_non_null(b);
|
assert_non_null(b);
|
||||||
assert_int_equal(b->length, last_length);
|
assert_int_equal(b->length, last_length);
|
||||||
|
|
||||||
isc_buffer_setautorealloc(b, true);
|
|
||||||
|
|
||||||
isc_buffer_putuint8(b, 1);
|
isc_buffer_putuint8(b, 1);
|
||||||
|
|
||||||
for (i = 0; i < 1000; i++) {
|
for (i = 0; i < 1000; i++) {
|
||||||
@@ -166,16 +164,9 @@ ISC_RUN_TEST_IMPL(isc_buffer_copyregion) {
|
|||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Appending more data to the buffer should fail.
|
* Appending should succeed.
|
||||||
*/
|
*/
|
||||||
result = isc_buffer_copyregion(b, &r);
|
result = isc_buffer_copyregion(b, &r);
|
||||||
assert_int_equal(result, ISC_R_NOSPACE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enable auto reallocation and retry. Appending should now succeed.
|
|
||||||
*/
|
|
||||||
isc_buffer_setautorealloc(b, true);
|
|
||||||
result = isc_buffer_copyregion(b, &r);
|
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
isc_buffer_free(&b);
|
isc_buffer_free(&b);
|
||||||
@@ -196,7 +187,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_printf) {
|
|||||||
*/
|
*/
|
||||||
b = NULL;
|
b = NULL;
|
||||||
isc_buffer_allocate(mctx, &b, 0);
|
isc_buffer_allocate(mctx, &b, 0);
|
||||||
isc_buffer_setautorealloc(b, true);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sanity check.
|
* Sanity check.
|
||||||
|
Reference in New Issue
Block a user