BUG/MEDIUM: ssl_sample: fix segfault for srv samples on invalid request
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 21 Jul 2021 09:50:12 +0000 (11:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Jul 2021 06:37:05 +0000 (08:37 +0200)
commit20d15662a56b9402d3d34a18aba851c45c14b22e
treeab03e1a576d116381a82cb55b746001968272443
parentadf901b3dec32994a39ec6cb0ba5625afdeca319
BUG/MEDIUM: ssl_sample: fix segfault for srv samples on invalid request

Some ssl samples cause a segfault when the stream is not instantiated,
for example during an invalid HTTP request. A new check is added to
prevent the stream dereferencing if NULL.

This is the list of the affected samples :
- ssl_s_chain_der
- ssl_s_der
- ssl_s_i_dn
- ssl_s_key_alg
- ssl_s_notafter
- ssl_s_notbefore
- ssl_s_s_dn
- ssl_s_serial
- ssl_s_sha1
- ssl_s_sig_alg
- ssl_s_version

This bug can be reproduced easily by using one of these samples in a
log-format string. Emit an invalid HTTP request with an HTTP client to
trigger the crash.

This bug has been reported in redmine issue 3913.

This must be backported up to 2.2.

(cherry picked from commit 5fcd428c35c45f7222b9aade0c0484fcdb558de9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 73617f937e001514305a3ee5a259bf45a3f0961b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/ssl_sample.c