]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enable auto-reallocation for all isc_buffer_allocate() buffers
authorOndřej Surý <ondrej@isc.org>
Thu, 15 Dec 2022 21:27:12 +0000 (22:27 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 20 Dec 2022 18:13:48 +0000 (19:13 +0100)
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.

lib/dns/catz.c
lib/isc/buffer.c
lib/isc/httpd.c
lib/isc/include/isc/buffer.h
lib/isc/netmgr/http.c
tests/isc/buffer_test.c

index 600a9bb345d79b4f69caf7cd71d1ceb380d86f33..56d4ed65bb475beb0202eeb18585f2e84e01555f 100644 (file)
@@ -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");
index c1630bfdb681945dcada6754e587b8b5747bd19c..8d9873adad673b426aa5c51d04b3d6c2a1ec5fd5 100644 (file)
@@ -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);
index 039de4da1ab01f661cdcf8c71e1624bad3a61d02..6cdd5b01cac358344dabf16989b3a88ad0dbd36f 100644 (file)
@@ -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);
 
index 6247a89456c94f81296dd0d1b0af269fc66734f7..6ce0ba45ce5e706122553e5991d2601879f4ae66 100644 (file)
@@ -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);
        }
index cf04ac3d46649e8d49d11d2fd07a04884a0986cc..7cb69b5f97ee609d352afb596e651b75584e4047 100644 (file)
@@ -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]])
index fc205e993dd237fa49194dd82ae435c219706b59..94ed6f8017691eca8db17106093cddd5ae3e7dcb 100644 (file)
@@ -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.