From 76e047fc27b3a0b9e6d6d00cacf536e7b7c1b532 Mon Sep 17 00:00:00 2001 From: Jeff Mears Date: Fri, 6 Aug 2021 14:27:42 -0700 Subject: easy: use a custom implementation of wcsdup on Windows ... so that malloc/free overrides from curl_global_init are used for wcsdup correctly. Closes #7540 --- lib/strdup.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/strdup.c') diff --git a/lib/strdup.c b/lib/strdup.c index 9af47ea47..05ccdfa8f 100644 --- a/lib/strdup.c +++ b/lib/strdup.c @@ -24,6 +24,10 @@ #include +#ifdef WIN32 +#include +#endif + #include "strdup.h" #include "curl_memory.h" @@ -50,6 +54,28 @@ char *curlx_strdup(const char *str) } #endif +#ifdef WIN32 +/*************************************************************************** + * + * Curl_wcsdup(source) + * + * Copies the 'source' wchar string to a newly allocated buffer (that is + * returned). + * + * Returns the new pointer or NULL on failure. + * + ***************************************************************************/ +wchar_t *Curl_wcsdup(const wchar_t *src) +{ + size_t length = wcslen(src); + + if(length > (SIZE_T_MAX / sizeof(wchar_t)) - 1) + return (wchar_t *)NULL; /* integer overflow */ + + return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t)); +} +#endif + /*************************************************************************** * * Curl_memdup(source, length) -- cgit v1.2.1