]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: vars: make smp_fetch_var() more robust against misuses
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Oct 2016 15:14:35 +0000 (17:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Oct 2016 15:53:46 +0000 (17:53 +0200)
smp_fetch_var() may be called from everywhere since it just reads a
variable. It must ensure that the stream exists before trying to return
a stream-dependant variable. For now there is no impact but it will
cause trouble with tcp-request session rules.

src/vars.c

index b22c3bf2abc5a2804a8a319f6f61e819a72ad09c..4a0c4ed350022d5bb30e9fbdeac51d7d377fe718 100644 (file)
@@ -242,11 +242,21 @@ static int smp_fetch_var(const struct arg *args, struct sample *smp, const char
 
        /* Check the availibity of the variable. */
        switch (var_desc->scope) {
-       case SCOPE_SESS: vars = &smp->sess->vars;  break;
-       case SCOPE_TXN:  vars = &smp->strm->vars_txn;    break;
+       case SCOPE_SESS:
+               vars = &smp->sess->vars;
+               break;
+       case SCOPE_TXN:
+               if (!smp->strm)
+                       return 0;
+               vars = &smp->strm->vars_txn;
+               break;
        case SCOPE_REQ:
        case SCOPE_RES:
-       default:         vars = &smp->strm->vars_reqres; break;
+       default:
+               if (!smp->strm)
+                       return 0;
+               vars = &smp->strm->vars_reqres;
+               break;
        }
        if (vars->scope != var_desc->scope)
                return 0;