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>
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
*/
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);