]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: chunk: make chunk_dup() always check and set dst->size
authorWilly Tarreau <w@1wt.eu>
Mon, 4 Jan 2016 19:36:59 +0000 (20:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 4 Jan 2016 19:47:27 +0000 (20:47 +0100)
commitf9476a5a308df570239ab0a57de2759600dd9cc2
treeddd541fd069e1df53e7fea3fe01f9a9858982616
parenta94e5a548c9badbccde5e989f75bca5991a7b15d
BUG/MINOR: chunk: make chunk_dup() always check and set dst->size

chunk_dup() was affected by two bugs at once related to dst->size :
  - first, it didn't check dst->size to know if it could free(dst->str),
    so using it on a statically allocated chunk would cause a free(constant)
    and crash the process ;

  - second, it didn't properly set dst->size, possibly causing smaller
    strings not to be properly reported in a chunk that was previously
    used for something else.

Fortunately, neither of these situations ever happened since the function
is rarely used.

In the process of doing this, we even allocate one more byte for a
trailing zero if the input chunk was not full, so that the copied
string can safely be reused by standard string functions.

The bug was introduced in 1.3.4 nine years ago with this commit :

  0f77253 ("[MINOR] store HTTP error messages into a chunk array")

It's better to backport this fix in case a future fix relies on it.
include/common/chunk.h