Don't allocate more than is needed in BUF_strndup().
authorBen Laurie <ben@links.org>
Tue, 20 May 2014 12:52:31 +0000 (13:52 +0100)
committerBen Laurie <ben@links.org>
Tue, 20 May 2014 12:52:31 +0000 (13:52 +0100)
crypto/buffer/buf_str.c

index 11241f8..a464eb6 100644 (file)
@@ -71,9 +71,14 @@ char *BUF_strdup(const char *str)
 char *BUF_strndup(const char *str, size_t siz)
        {
        char *ret;
+       size_t len;
 
        if (str == NULL) return(NULL);
 
+       len = strlen(str);
+       if (siz > len)
+           siz = len;
+
        ret=OPENSSL_malloc(siz+1);
        if (ret == NULL) 
                {