BUG/MAJOR: samples: check smp->strm before using it
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Mar 2016 10:47:01 +0000 (11:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Mar 2016 15:42:58 +0000 (16:42 +0100)
commitbe508f158077cab6ed65581cd0e66d5908cf61da
treea42514e0e70e269637eab97ac2df648d4a375f5d
parent1a786d7f33267efbbd352b8fb0442f215ee97cfd
BUG/MAJOR: samples: check smp->strm before using it

Since commit 6879ad3 ("MEDIUM: sample: fill the struct sample with the
session, proxy and stream pointers") merged in 1.6-dev2, the sample
contains the pointer to the stream and sample fetch functions as well
as converters use it heavily.

The problem is that earlier commit 87b0966 ("REORG/MAJOR: session:
rename the "session" entity to "stream"") had split the session and
stream resulting in the possibility for smp->strm to be NULL before
the stream was initialized. This is what happens in tcp-request
connection rulesets, as discovered by Baptiste.

The sample fetch functions must now check that smp->strm is valid
before using it. An alternative could consist in using a dummy stream
with nothing in it to avoid some checks but it would only result in
deferring them to the next step anyway, and making it harder to detect
that a stream is valid or the dummy one.

There is still an issue with variables which requires a complete
independant fix. They use strm->sess to find the session with strm
possibly NULL and passed as an argument. All call places indirectly
use smp->strm to build strm. So the problem is there but the API needs
to be changed to remove this duplicate argument that makes it much
harder to know what pointer to use.

This fix must be backported to 1.6, as well as the next one fixing
variables.
include/types/sample.h
src/backend.c
src/flt_http_comp.c
src/hlua.c
src/payload.c
src/proto_http.c
src/ssl_sock.c
src/stream.c