aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssl/crypto/buffer/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/crypto/buffer/buffer.c')
-rw-r--r--crypto/openssl/crypto/buffer/buffer.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/crypto/openssl/crypto/buffer/buffer.c b/crypto/openssl/crypto/buffer/buffer.c
index d96487e7dbd0..3bf03c7eff07 100644
--- a/crypto/openssl/crypto/buffer/buffer.c
+++ b/crypto/openssl/crypto/buffer/buffer.c
@@ -149,7 +149,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
ret=OPENSSL_realloc_clean(str->data,str->max,n);
if (ret == NULL)
{
- BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
+ BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE);
len=0;
}
else
@@ -164,22 +164,41 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
char *BUF_strdup(const char *str)
{
+ if (str == NULL) return(NULL);
+ return BUF_strndup(str, strlen(str));
+ }
+
+char *BUF_strndup(const char *str, size_t siz)
+ {
char *ret;
- int n;
if (str == NULL) return(NULL);
- n=strlen(str);
- ret=OPENSSL_malloc(n+1);
+ ret=OPENSSL_malloc(siz+1);
if (ret == NULL)
{
- BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
+ BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE);
return(NULL);
}
- memcpy(ret,str,n+1);
+ BUF_strlcpy(ret,str,siz+1);
return(ret);
}
+void *BUF_memdup(const void *data, size_t siz)
+ {
+ void *ret;
+
+ if (data == NULL) return(NULL);
+
+ ret=OPENSSL_malloc(siz);
+ if (ret == NULL)
+ {
+ BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE);
+ return(NULL);
+ }
+ return memcpy(ret, data, siz);
+ }
+
size_t BUF_strlcpy(char *dst, const char *src, size_t size)
{
size_t l = 0;