mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-15 21:59:41 -04:00
CLEANUP: chunk: adding NULL check to chunk_dup allocation.
Avoiding harmful memcpy call if the allocation failed. Resetting the size which avoids further harmful freeing invalid pointer. Closer to the comment behavior description.
This commit is contained in:
parent
0b547059ec
commit
8ab1043c6b
1 changed files with 6 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue