BUG/MINOR: http_ana/txn: don't re-initialize txn and req var lists
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 18 Nov 2022 08:17:29 +0000 (09:17 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 18 Nov 2022 09:20:44 +0000 (10:20 +0100)
commit5ad2b642625b89cdf4f5fd26a598fc480abdc806
treeb9b8e42b94b2a7c3089e03cbcaf70e6015bad814
parentce7928d19c6e9a1b9622dbf79f9e17af71bd2d4b
BUG/MINOR: http_ana/txn: don't re-initialize txn and req var lists

In http_create_txn(): vars_init_head() was performed on both s->vars_txn
and s->var_reqres lists.

But this is wrong, these two lists are already initialized upon stream
creation in stream_new().
Moreover, between stream_new() and http_create_txn(), some variable may
be defined (e.g.: by the frontend), resulting in lists not being empty.

Because of this "extra" list initialization, already defined variables
can be lost.
This causes txn dependant code not being able to access previously defined
variables as well as memory leak because http_destroy_txn() relies on these
lists to perform the purge.

This proved to be the case when a frontend sets variables and lua sample
fetch is used in backend section as described in GH #1935.
Many thanks to Darragh O'Toole for his detailed report.

Removing extra var_init_head (x2) in http_create_txn() to fix the issue.
Adding somme comments in the code in an attempt to prevent future misuses
of s->var_reqres, and s->var_txn lists.

It should be backported in every stable version.
(This is an old bug that seems to exist since 1.6-dev6)

[cf: On 2.0 and 1.8, for the legacy HTTP code, vars_init() are used during
     the TXN cleanup, when the stream is reused. So, these calls must be
     moved from http_init_txn() to http_reset_txn() and not removed.]
src/http_ana.c
src/stream.c