BUG/MINOR: ssl: fix memcpy overlap without consequences.
authorEmeric Brun <ebrun@haproxy.com>
Tue, 8 Oct 2019 16:27:37 +0000 (18:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Oct 2019 16:57:45 +0000 (18:57 +0200)
commiteb46965bbb21291aab75ae88f033d9c9bab4a785
tree2686189330fd95095df73ee2caa8f82d9ed020c3
parent25e6fc2030552499e42f202a2496e7f9bc634005
BUG/MINOR: ssl: fix memcpy overlap without consequences.

A trick is used to set SESSION_ID, and SESSION_ID_CONTEXT lengths
to 0 and avoid ASN1 encoding of these values.

There is no specific function to set the length of those parameters
to 0 so we fake this calling these function to a different value
with the same buffer but a length to zero.

But those functions don't seem to check the length of zero before
performing a memcpy of length zero but with src and dst buf on the
same pointer, causing valgrind to bark.

So the code was re-work to pass them different pointers even
if buffer content is un-used.

In a second time, reseting value, a memcpy overlap
happened on the SESSION_ID_CONTEXT. It was re-worked and this is
now reset using the constant global value SHCTX_APPNAME which is a
different pointer with the same content.

This patch should be backported in every version since ssl
support was added to haproxy if we want valgrind to shut up.
This is tracked in github issue #56.
src/ssl_sock.c