]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove isc_mem_strndup() 12240/head
authorOndřej Surý <ondrej@isc.org>
Fri, 12 Jun 2026 14:17:46 +0000 (16:17 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 12 Jun 2026 15:40:05 +0000 (17:40 +0200)
The function had a single caller, the HTTP/2 request-path handling in
the network manager, and its semantics (strlen() of the source clamped
to the requested size) amounted to an obscured bounded string copy.
Replace the only use with a plain allocation and strlcpy(), and drop the
function.

lib/isc/include/isc/mem.h
lib/isc/mem.c
lib/isc/netmgr/http.c

index 03a6aeba9081e62facb582394ff11b5d412afcbd..2eece8021de5b1261c34b4872d4aac95fbf67d90 100644 (file)
@@ -142,9 +142,7 @@ extern isc_mem_t *isc_g_mctx;
 #define isc_mem_reallocate(c, p, s) \
        isc__mem_reallocate((c), (p), (s), 0 _ISC_MEM_FILELINE)
 #define isc_mem_strdup(c, p) isc__mem_strdup((c), (p)_ISC_MEM_FILELINE)
-#define isc_mem_strndup(c, p, l) \
-       isc__mem_strndup((c), (p), (l)_ISC_MEM_FILELINE)
-#define isc_mempool_get(c) isc__mempool_get((c)_ISC_MEM_FILELINE)
+#define isc_mempool_get(c)   isc__mempool_get((c)_ISC_MEM_FILELINE)
 
 #define isc_mem_put(c, p, s)                                      \
        do {                                                      \
@@ -465,11 +463,6 @@ ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
 char *
 isc__mem_strdup(isc_mem_t *, const char *_ISC_MEM_FLARG);
 
-ISC_ATTR_RETURNS_NONNULL
-ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
-char *
-isc__mem_strndup(isc_mem_t *, const char *, size_t _ISC_MEM_FLARG);
-
 ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mempool_put, 2)
 void *
 isc__mempool_get(isc_mempool_t *_ISC_MEM_FLARG);
index fd594d8ebe4ad39872dd53cb566562cbb4a0636e..cd3a8e5a89c794539d882b13bdde3452c23e21e7 100644 (file)
@@ -960,27 +960,6 @@ isc__mem_strdup(isc_mem_t *mctx, const char *s FLARG) {
        return ns;
 }
 
-char *
-isc__mem_strndup(isc_mem_t *mctx, const char *s, size_t size FLARG) {
-       size_t len;
-       char *ns = NULL;
-
-       REQUIRE(VALID_CONTEXT(mctx));
-       REQUIRE(s != NULL);
-       REQUIRE(size != 0);
-
-       len = strlen(s) + 1;
-       if (len > size) {
-               len = size;
-       }
-
-       ns = isc__mem_allocate(mctx, len, 0 FLARG_PASS);
-
-       strlcpy(ns, s, len);
-
-       return ns;
-}
-
 void
 isc_mem_setdestroycheck(isc_mem_t *ctx, bool flag) {
        REQUIRE(VALID_CONTEXT(ctx));
index 79357ff3f9d6e8ddb6571da11704cb65cd859b6a..94f38485d8a21d8272d4f4c699ba3ee2874b676a 100644 (file)
@@ -2170,8 +2170,9 @@ server_handle_path_header(isc_nmsocket_t *socket, const uint8_t *value,
        if (socket->h2->request_path != NULL) {
                isc_mem_free(socket->worker->mctx, socket->h2->request_path);
        }
-       socket->h2->request_path = isc_mem_strndup(
-               socket->worker->mctx, (const char *)value, vlen + 1);
+       socket->h2->request_path = isc_mem_allocate(socket->worker->mctx,
+                                                   vlen + 1);
+       strlcpy(socket->h2->request_path, (const char *)value, vlen + 1);
 
        if (!isc_nm_http_path_isvalid(socket->h2->request_path)) {
                isc_mem_free(socket->worker->mctx, socket->h2->request_path);