From 2c897d9d1bf25bef36f717edc6bbc38926ab8d91 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 31 Aug 2021 08:48:55 +0200 Subject: [PATCH] MINOR: vars: preset a random seed to hash variables names 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/vars.c b/src/vars.c index 30bcf3df9..cefd02a03 100644 --- a/src/vars.c +++ b/src/vars.c @@ -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)