From: Nikos Mavrogiannopoulos Date: Sun, 27 Apr 2014 15:59:19 +0000 (+0200) Subject: tolerate NULL in strdup(). Patch by shawn (sth0r2046 [at] gmail.com). X-Git-Tag: gnutls_3_3_2~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1a375376f9876b1f8308e5ff135366348ede063;p=thirdparty%2Fgnutls.git tolerate NULL in strdup(). Patch by shawn (sth0r2046 [at] gmail.com). --- diff --git a/lib/gnutls_mem.c b/lib/gnutls_mem.c index 8c24420770..d2da8b0ffe 100644 --- a/lib/gnutls_mem.c +++ b/lib/gnutls_mem.c @@ -63,9 +63,14 @@ void *gnutls_realloc_fast(void *ptr, size_t size) char *_gnutls_strdup(const char *str) { - size_t siz = strlen(str) + 1; + size_t siz; char *ret; + if(unlikely(!str)) + return NULL; + + siz = strlen(str) + 1; + ret = gnutls_malloc(siz); if (ret != NULL) memcpy(ret, str, siz);