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 11241f87273a532dc0ac6d1ac6337a95d5346905..a464eb6e25605eb71df850ebba1c8f45f7a39628 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) 
                {