]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: stick-table: don't deinit the buckets of a never initialized table
authorBruno Henc <hencb@protonmail.com>
Thu, 5 Nov 2026 06:28:06 +0000 (07:28 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Nov 2026 14:13:38 +0000 (15:13 +0100)
stktable_init() is skipped for the table of a disabled proxy, so its
buckets' in_bucket_toadd lists are never initialized. stktable_deinit()
still calls MT_LIST_DELETE() on them when the proxy is freed, and
mt_list_delete() dereferences their NULL pointers. As a result, a config
with a disabled backend declaring a stick-table segfaults at the end of
"haproxy -c" (exit 139) and on every graceful stop, so on every reload.

Only walk the buckets once the table was initialized, which t->pool
tells. The rest of the function is already safe on a never initialized
table.

This was introduced with the per-bucket expiration tasks in commit
8bc8a21b2 ("MEDIUM: stick-tables: Use a per-shard expiration task"),
3.3-dev11, so it must be backported to 3.3.

It should fix the issue #3581.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/stick_table.c

index 7c6a57d791f64e88f06ade76100b30ccd3429be1..7f2a431809fa9b6b71a3277e1d4e4cd42970af22 100644 (file)
@@ -1264,9 +1264,9 @@ int stktable_init(struct stktable *t, char **err_msg)
        return 0;
 }
 
-/* Performs stick table cleanup: it's meant to be called after the table
- * has been initialized ith stktable_init(), else it will lead to undefined
- * behavior.
+/* Performs stick table cleanup. It may be called on a table that was never
+ * initialized with stktable_init(), e.g. the table of a disabled proxy, which
+ * is skipped at init time: its buckets were never set up and are left alone.
  *
  * However it does not free the table pointer itself
  */
@@ -1276,7 +1276,8 @@ void stktable_deinit(struct stktable *t)
 
        if (!t)
                return;
-       for (i = 0; i < CONFIG_HAP_TBL_BUCKETS; i++) {
+       /* t->pool is only set once stktable_init() has set up the buckets */
+       for (i = 0; t->pool && i < CONFIG_HAP_TBL_BUCKETS; i++) {
                HA_SPIN_LOCK(OTHER_LOCK, &per_bucket[i].lock);
                eb32_delete(&t->buckets[i].in_bucket);
                MT_LIST_DELETE(&t->buckets[i].in_bucket_toadd);