]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sample: Make sure to return stable IDs in the unique-id fetch
authorTim Duesterhus <tim@bastelstu.be>
Wed, 26 Feb 2020 15:20:49 +0000 (16:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 27 Feb 2020 02:50:10 +0000 (03:50 +0100)
Previously when the `unique-id-format` contained non-deterministic parts,
such as the `uuid` fetch each use of the `unique-id` fetch would generate
a new unique ID, replacing the old one. The following configuration shows
the error:

  global
        log stdout format short daemon

  listen test
        log global
        log-format "%ID"
        unique-id-format %{+X}o\ TEST-%[uuid]

        mode http
        bind *:8080
        http-response set-header A %[unique-id]
        http-response set-header B %[unique-id]
        server example example.com:80

Without the patch the contents of the `A` and `B` response header would
differ.

This bug was introduced in commit f4011ddcf5b41284d2b137e84c25f2d1264ce458,
which was first released with HAProxy 1.7-dev3.

This fix should be backported to HAProxy 1.7+.

src/http_fetch.c

index 29a5d17d82ef7ba1d1b04349ad31f95bdcb4a721..d288e841dad3dfdbf152eaa6cb43041254c9c9b0 100644 (file)
@@ -416,10 +416,10 @@ static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const
                if ((smp->strm->unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
                        return 0;
                smp->strm->unique_id[0] = '\0';
+               build_logline(smp->strm, smp->strm->unique_id,
+                             UNIQUEID_LEN, &smp->sess->fe->format_unique_id);
        }
-       smp->data.u.str.data = build_logline(smp->strm, smp->strm->unique_id,
-                                           UNIQUEID_LEN, &smp->sess->fe->format_unique_id);
-
+       smp->data.u.str.data = strlen(smp->strm->unique_id);
        smp->data.type = SMP_T_STR;
        smp->data.u.str.area = smp->strm->unique_id;
        smp->flags = SMP_F_CONST;