From: Ondřej Surý Date: Thu, 15 Dec 2022 21:27:12 +0000 (+0100) Subject: Enable auto-reallocation for all isc_buffer_allocate() buffers X-Git-Tag: v9.19.9~69^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6bd2b34180d74146423a6c637f58d3bb8164a29c;p=thirdparty%2Fbind9.git 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. --- diff --git a/lib/dns/catz.c b/lib/dns/catz.c index 600a9bb345d..56d4ed65bb4 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -1548,7 +1548,6 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp, return (result); } 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; 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_setautorealloc(buffer, true); isc_buffer_putstr(buffer, "zone \""); dns_name_totext(&entry->name, true, buffer); isc_buffer_putstr(buffer, "\" { type secondary; primaries"); diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index c1630bfdb68..8d9873adad6 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -36,7 +36,7 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) { */ REQUIRE(b->length <= length); REQUIRE(base != NULL); - REQUIRE(!b->autore); + REQUIRE(b->mctx == NULL); if (b->length > 0U) { (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; } -void -isc_buffer_setautorealloc(isc_buffer_t *b, bool enable) { - REQUIRE(ISC_BUFFER_VALID(b)); - REQUIRE(b->mctx != NULL); - b->autore = enable; -} - void isc_buffer_compact(isc_buffer_t *b) { 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(r != NULL); - if (b->autore) { + if (b->mctx) { result = isc_buffer_reserve(b, r->length); if (result != ISC_R_SUCCESS) { return (result); @@ -136,8 +129,6 @@ isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer, isc_buffer_init(dbuf, bdata, length); - ENSURE(ISC_BUFFER_VALID(dbuf)); - dbuf->mctx = mctx; *dynbuffer = dbuf; @@ -213,7 +204,7 @@ isc_buffer_printf(isc_buffer_t *b, const char *format, ...) { return (ISC_R_FAILURE); } - if (b->autore) { + if (b->mctx) { result = isc_buffer_reserve(b, n + 1); if (result != ISC_R_SUCCESS) { return (result); diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 039de4da1ab..6cdd5b01cac 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -562,7 +562,6 @@ isc__httpd_sendreq_new(isc_httpd_t *httpd) { */ isc_buffer_allocate(req->mctx, &req->sendbuffer, HTTP_SENDLEN); isc_buffer_clear(req->sendbuffer); - isc_buffer_setautorealloc(req->sendbuffer, true); isc_buffer_initnull(&req->bodybuffer); diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index 6247a89456c..6ce0ba45ce5 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -182,8 +182,6 @@ struct isc_buffer { ISC_LINK(isc_buffer_t) link; /*! private internal elements */ 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 isc_buffer_compact(isc_buffer_t *b); /*!< @@ -854,7 +842,7 @@ isc_buffer_getuint8(isc_buffer_t *b) { { \ REQUIRE(ISC_BUFFER_VALID(b)); \ \ - if (b->autore) { \ + if (b->mctx) { \ isc_result_t result = isc_buffer_reserve(b, \ sizeof(val)); \ ENSURE(result == ISC_R_SUCCESS); \ @@ -969,7 +957,7 @@ isc_buffer_putmem(isc_buffer_t *b, const unsigned char *base, unsigned int length) { ISC_REQUIRE(ISC_BUFFER_VALID(b)); - if (b->autore) { + if (b->mctx) { isc_result_t result = isc_buffer_reserve(b, length); ISC_REQUIRE(result == ISC_R_SUCCESS); } @@ -1005,7 +993,7 @@ isc_buffer_putstr(isc_buffer_t *b, const char *source) { ISC_REQUIRE(source != NULL); length = (unsigned int)strlen(source); - if (b->autore) { + if (b->mctx) { isc_result_t result = isc_buffer_reserve(b, length); ISC_ENSURE(result == ISC_R_SUCCESS); } diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index cf04ac3d466..7cb69b5f97e 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -443,7 +443,6 @@ new_http_cstream(isc_nmsocket_t *sock, http_cstream_t **streamp) { isc_buffer_allocate(mctx, &stream->rbuf, INITIAL_DNS_MESSAGE_BUFFER_SIZE); - isc_buffer_setautorealloc(stream->rbuf, true); ISC_LIST_PREPEND(sock->h2.session->cstreams, stream, link); *streamp = stream; @@ -1005,7 +1004,6 @@ http_readcb(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region, if (session->buf == NULL) { isc_buffer_allocate(session->mctx, &session->buf, unread_size); - isc_buffer_setautorealloc(session->buf, true); } isc_buffer_putmem(session->buf, region->base + readlen, unread_size); @@ -1121,8 +1119,6 @@ http_send_outgoing(isc_nm_http_session_t *session, isc_nmhandle_t *httphandle, isc_buffer_allocate(session->mctx, &session->pending_write_data, INITIAL_DNS_MESSAGE_BUFFER_SIZE); - isc_buffer_setautorealloc(session->pending_write_data, - true); } isc_buffer_putmem(session->pending_write_data, data, pending); 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 (!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); session->reading = true; } else if (session->buf != NULL) { size_t remaining = 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( session->ngsession, 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); return; } 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); } } else { @@ -1406,9 +1406,10 @@ transport_connect_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { NGHTTP2_PROTO_VERSION_ID_LEN) != 0) { /* - * HTTP/2 negotiation error. Any sensible DoH - * client will fail if HTTP/2 cannot be - * negotiated via ALPN. + * HTTP/2 negotiation error. + * Any sensible DoH client + * will fail if HTTP/2 cannot + * be negotiated via ALPN. */ result = ISC_R_HTTP2ALPNERROR; goto error; @@ -2346,9 +2347,12 @@ server_on_frame_recv_callback(nghttp2_session *ngsession, ngsession, frame->hd.stream_id); /* - * For DATA and HEADERS frame, this callback may be - * called after on_stream_close_callback. Check that - * the stream is still alive. + * For DATA and HEADERS frame, + * this callback may be called + * after + * on_stream_close_callback. + * Check that the stream is + * still alive. */ if (socket == NULL) { return (0); @@ -3168,9 +3172,12 @@ isc__nm_base64_to_base64url(isc_mem_t *mem, const char *base64, break; default: /* - * All other characters from the alphabet are the same - * for both base64 and base64url, so we can reuse the - * validation table for the rest of the characters. + * All other characters from + * the alphabet are the same + * for both base64 and + * base64url, so we can reuse + * the validation table for + * the rest of the characters. */ if (base64[i] != '-' && base64[i] != '_' && base64url_validation_table[(size_t)base64[i]]) diff --git a/tests/isc/buffer_test.c b/tests/isc/buffer_test.c index fc205e993dd..94ed6f80176 100644 --- a/tests/isc/buffer_test.c +++ b/tests/isc/buffer_test.c @@ -113,8 +113,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_dynamic) { assert_non_null(b); assert_int_equal(b->length, last_length); - isc_buffer_setautorealloc(b, true); - isc_buffer_putuint8(b, 1); for (i = 0; i < 1000; i++) { @@ -166,15 +164,8 @@ ISC_RUN_TEST_IMPL(isc_buffer_copyregion) { assert_int_equal(result, ISC_R_SUCCESS); /* - * Appending more data to the buffer should fail. - */ - result = isc_buffer_copyregion(b, &r); - assert_int_equal(result, ISC_R_NOSPACE); - - /* - * Enable auto reallocation and retry. Appending should now succeed. + * Appending should succeed. */ - isc_buffer_setautorealloc(b, true); result = isc_buffer_copyregion(b, &r); assert_int_equal(result, ISC_R_SUCCESS); @@ -196,7 +187,6 @@ ISC_RUN_TEST_IMPL(isc_buffer_printf) { */ b = NULL; isc_buffer_allocate(mctx, &b, 0); - isc_buffer_setautorealloc(b, true); /* * Sanity check.