]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: stick_table: fix crash when using tcp smp_fetch_src
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 12 May 2021 08:17:47 +0000 (10:17 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 12 May 2021 13:30:03 +0000 (15:30 +0200)
Since the introduction of bc_src, smp_fetch_src from tcp_sample inspect
the kw argument to choose between the frontend or the backend source
address. However, for the stick tables, the argument is left to NULL.
This causes a segfault.

Fix the crash by explicitely set the kw argument to "src" to retrieve
the source address of the frontend side.

This bug was introduced by the following commit :
  7d081f02a43651d781a3a30a51ae19abdceb5683
  MINOR: tcp_samples: Add samples to get src/dst info of the backend connection

It does not need a backport as it is integrated in the current 2.4-dev
branch.

To reproduce the crash, I used the following config :

frontend fe
bind :20080
http-request track-sc0 src table foo
http-request reject if { src_conn_rate(foo) gt 10 }
use_backend h1

backend foo
stick-table type ip size 200k expire 30s store conn_rate(60s)

backend h1
server nginx 127.0.0.1:30080 check

This should fix the github issue #1247.

src/stick_table.c

index d16e1d01b1351caa7f2259ed0ba636227d1b22ca..51aaef3d6e117dc170759f0cefa5f2dc122d3d4d 100644 (file)
@@ -2362,7 +2362,7 @@ smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg
                smp.px = NULL;
                smp.sess = sess;
                smp.strm = strm;
-               if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, NULL, NULL))
+               if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
                        return NULL;
 
                /* Converts into key. */
@@ -2427,7 +2427,7 @@ smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct ar
        smp.px = NULL;
        smp.sess = sess;
        smp.strm = strm;
-       if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, NULL, NULL))
+       if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, &smp, "src", NULL))
                return NULL;
 
        /* Converts into key. */
@@ -2959,7 +2959,7 @@ smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const ch
                return 0;
 
        /* Fetch source address in a sample. */
-       if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, smp, NULL, NULL))
+       if (!smp_fetch_src || !smp_fetch_src(empty_arg_list, smp, "src", NULL))
                return 0;
 
        /* Converts into key. */