diff options
author | Emilia Kasper <emilia@openssl.org> | 2015-09-17 13:27:05 +0200 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2015-09-22 20:04:01 +0200 |
commit | f5afe9ce3f7ab8d2fef460054d1170427db0d02c (patch) | |
tree | 0ce553523ddf7b4f4cbad881e44b96181001462b /crypto/buffer | |
parent | f61216ba9d17430fb5eb3e2b202a209960b9d51b (diff) |
BUF_strndup: tidy
Fix comment, add another overflow check, tidy style
Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit de8883e11befde31d9b6cfbbd1fc017c365e0bbf)
Diffstat (limited to 'crypto/buffer')
-rw-r--r-- | crypto/buffer/buf_str.c | 14 | ||||
-rw-r--r-- | crypto/buffer/buffer.h | 4 |
2 files changed, 9 insertions, 9 deletions
diff --git a/crypto/buffer/buf_str.c b/crypto/buffer/buf_str.c index 61024cf5ed..fa0d608e76 100644 --- a/crypto/buffer/buf_str.c +++ b/crypto/buffer/buf_str.c @@ -73,7 +73,7 @@ size_t BUF_strnlen(const char *str, size_t maxlen) char *BUF_strdup(const char *str) { if (str == NULL) - return (NULL); + return NULL; return BUF_strndup(str, strlen(str)); } @@ -82,17 +82,17 @@ char *BUF_strndup(const char *str, size_t siz) char *ret; if (str == NULL) - return (NULL); + return NULL; siz = BUF_strnlen(str, siz); if (siz >= INT_MAX) - return (NULL); + return NULL; ret = OPENSSL_malloc(siz + 1); if (ret == NULL) { BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); - return (NULL); + return NULL; } memcpy(ret, str, siz); @@ -105,13 +105,13 @@ void *BUF_memdup(const void *data, size_t siz) { void *ret; - if (data == NULL) - return (NULL); + if (data == NULL || siz >= INT_MAX) + return NULL; ret = OPENSSL_malloc(siz); if (ret == NULL) { BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE); - return (NULL); + return NULL; } return memcpy(ret, data, siz); } diff --git a/crypto/buffer/buffer.h b/crypto/buffer/buffer.h index a05cee091f..efd240a5f9 100644 --- a/crypto/buffer/buffer.h +++ b/crypto/buffer/buffer.h @@ -88,8 +88,8 @@ size_t BUF_strnlen(const char *str, size_t maxlen); char *BUF_strdup(const char *str); /* - * Returns a pointer to a new string which is a duplicate of the string |str|, - * but guarantees to never read past the first |siz| bytes of |str|. + * Like strndup, but in addition, explicitly guarantees to never read past the + * first |siz| bytes of |str|. */ char *BUF_strndup(const char *str, size_t siz); |