From: Ondřej Surý Date: Fri, 12 Jun 2026 14:17:46 +0000 (+0200) Subject: Remove isc_mem_strndup() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f068a307fd3f5ed4b435a77905938bcb27bf7e8;p=thirdparty%2Fbind9.git Remove isc_mem_strndup() 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. --- diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 03a6aeba908..2eece8021de 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -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); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index fd594d8ebe4..cd3a8e5a89c 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -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)); diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 79357ff3f9d..94f38485d8a 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -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);