]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: vars: preset a random seed to hash variables names
authorWilly Tarreau <w@1wt.eu>
Tue, 31 Aug 2021 06:48:55 +0000 (08:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:06:11 +0000 (15:06 +0200)
Variables names will be hashed, but for this we need a random seed.
The XXH3() algorithms is bijective over the whole 64-bit space, which
is great as it guarantees no collision for 1..8 byte names. But above
that even if the risk is extremely faint, it theoretically exists and
since variables may be set from Lua we'd rather do our best to limit
the risk of controlled collision, hence the random seed.

src/vars.c

index 30bcf3df9605ed23d2df32d68d088e1ab5c3d31b..cefd02a039988bb211a687ddcccf341feee52208 100644 (file)
@@ -42,6 +42,7 @@ static unsigned int var_sess_limit = 0;
 static unsigned int var_txn_limit = 0;
 static unsigned int var_reqres_limit = 0;
 static unsigned int var_check_limit = 0;
+static uint64_t var_name_hash_seed = 0;
 
 __decl_rwlock(var_names_rwlock);
 
@@ -1223,6 +1224,14 @@ static int vars_max_size_check(char **args, int section_type, struct proxy *curp
        return vars_max_size(args, section_type, curpx, defpx, file, line, err, &var_check_limit);
 }
 
+/* early boot initialization */
+static void vars_init()
+{
+       var_name_hash_seed = ha_random64();
+}
+
+INITCALL0(STG_PREPARE, vars_init);
+
 static void vars_deinit()
 {
        while (var_names_nb-- > 0)