From 63cdaefbc3a618f3d982ce239b3a9c1a7fd0e229 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 5 Dec 2023 15:55:35 +0100 Subject: [PATCH] strdup: remove the memchr check from Curl_strndup It makes it possible to clone a binary chunk of data. Closes #12453 --- lib/strdup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/strdup.c b/lib/strdup.c index 2578441c31..50f0656b91 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -104,18 +104,14 @@ void *Curl_memdup(const void *src, size_t length) * Curl_strndup(source, length) * * Copies the 'source' string to a newly allocated buffer (that is returned). - * Copies not more than 'length' bytes (up to a null terminator) then adds a - * null terminator. + * Copies 'length' bytes then adds a null terminator. * * Returns the new pointer or NULL on failure. * ***************************************************************************/ void *Curl_strndup(const char *src, size_t length) { - char *buf = memchr(src, '\0', length); - if(buf) - length = buf - src; - buf = malloc(length + 1); + char *buf = malloc(length + 1); if(!buf) return NULL; memcpy(buf, src, length);