]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: chunk: adding NULL check to chunk_dup allocation.
authorDavid Carlier <devnexen@gmail.com>
Wed, 23 Mar 2016 17:50:57 +0000 (17:50 +0000)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Mar 2016 09:18:44 +0000 (10:18 +0100)
Avoiding harmful memcpy call if the allocation failed.
Resetting the size which avoids further harmful freeing
invalid pointer. Closer to the comment behavior description.

include/common/chunk.h

index b74c767488ea72b2a6374bf1a13a029a79c871b7..aac5282fb15046b0b1730896740a76220499fe0f 100644 (file)
@@ -177,6 +177,12 @@ static inline char *chunk_dup(struct chunk *dst, const struct chunk *src)
                dst->size++;
 
        dst->str = (char *)malloc(dst->size);
+       if (!dst->str) {
+               dst->len = 0;
+               dst->size = 0;
+               return NULL;
+       }
+
        memcpy(dst->str, src->str, dst->len);
        if (dst->len < dst->size)
                dst->str[dst->len] = 0;