Commit e56c77b8 authored by Emilia Kasper's avatar Emilia Kasper
Browse files

BUF_strndup: tidy



Fix comment, add another overflow check, tidy style

Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
(cherry picked from commit de8883e1)
(cherry picked from commit f5afe9ce)
parent 69051874
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@
char *BUF_strdup(const char *str)
{
    if (str == NULL)
        return (NULL);
        return NULL;
    return BUF_strndup(str, strlen(str));
}

@@ -73,15 +73,15 @@ char *BUF_strndup(const char *str, size_t siz)
    char *ret;

    if (str == NULL)
        return (NULL);
        return NULL;

    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);
@@ -94,13 +94,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);
}
+2 −2
Original line number Diff line number Diff line
@@ -87,8 +87,8 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
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);