]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
memdup0: handle edge case
authorStefan Eissing <stefan@eissing.org>
Thu, 9 Oct 2025 09:42:43 +0000 (11:42 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 9 Oct 2025 12:43:56 +0000 (14:43 +0200)
When length is already SIZE_MAX, fail without allocating.

Reported-by: Joshua Rogers
Closes #18966

lib/strdup.c

index 66fd7c60eb5f030532b364430d964bcb483d76af..3339e909ee794b6ba76f8a20f37f5a7f34e60f0a 100644 (file)
@@ -111,7 +111,7 @@ void *Curl_memdup(const void *src, size_t length)
  ***************************************************************************/
 void *Curl_memdup0(const char *src, size_t length)
 {
-  char *buf = malloc(length + 1);
+  char *buf = (length < SIZE_MAX) ? malloc(length + 1) : NULL;
   if(!buf)
     return NULL;
   if(length) {