Don't allocate more than is needed in BUF_strndup().

This commit is contained in:
Ben Laurie 2014-05-20 13:52:31 +01:00
parent 81ce94f8dc
commit 4ceb430a46

View file

@ -69,9 +69,14 @@ char *BUF_strdup(const char *str)
char *BUF_strndup(const char *str, size_t siz) char *BUF_strndup(const char *str, size_t siz)
{ {
char *ret; char *ret;
size_t len;
if (str == NULL) return(NULL); if (str == NULL) return(NULL);
len = strlen(str);
if (siz > len)
siz = len;
ret=OPENSSL_malloc(siz+1); ret=OPENSSL_malloc(siz+1);
if (ret == NULL) if (ret == NULL)
{ {