diff options
author | Jeff Mears <jmears@blizzard.com> | 2021-08-06 14:27:42 -0700 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-08-09 14:08:42 +0200 |
commit | 76e047fc27b3a0b9e6d6d00cacf536e7b7c1b532 (patch) | |
tree | c89d56b7e41d528206edfff8f78568869ed30c4d | |
parent | 3e2a229783b8a8efe88574ec3b6e8c9d060e40e8 (diff) | |
download | curl-76e047fc27b3a0b9e6d6d00cacf536e7b7c1b532.tar.gz |
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
-rw-r--r-- | lib/easy.c | 2 | ||||
-rw-r--r-- | lib/strdup.c | 26 | ||||
-rw-r--r-- | lib/strdup.h | 3 |
3 files changed, 30 insertions, 1 deletions
diff --git a/lib/easy.c b/lib/easy.c index 588b1fb47..2aca93845 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -117,7 +117,7 @@ curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc; curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup; curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc; #if defined(WIN32) && defined(UNICODE) -curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup; +curl_wcsdup_callback Curl_cwcsdup = Curl_wcsdup; #endif #if defined(_MSC_VER) && defined(_DLL) && !defined(__POCC__) 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 <curl/curl.h> +#ifdef WIN32 +#include <wchar.h> +#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) diff --git a/lib/strdup.h b/lib/strdup.h index 0936956f8..5cbeaac9c 100644 --- a/lib/strdup.h +++ b/lib/strdup.h @@ -26,6 +26,9 @@ #ifndef HAVE_STRDUP extern char *curlx_strdup(const char *str); #endif +#ifdef WIN32 +wchar_t* Curl_wcsdup(const wchar_t* src); +#endif void *Curl_memdup(const void *src, size_t buffer_length); void *Curl_saferealloc(void *ptr, size_t size); |