]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: always check that requested alignment matches the type's
authorWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 14:47:17 +0000 (16:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 Aug 2025 17:55:30 +0000 (19:55 +0200)
For pool registrations that are created from the type declaration, we
now have the ability to verify that the requested alignment matches
the type's one. Let's not miss this opportunity, as we've met bugs in
the past that were caused by such mismatches. The principle is simple:
if the type alignment is known, we check that the configured alignment
is at least as large as that one otherwise we refuse to start (since
the code may crash at any moment). Obviously it doesn't crash for now!

src/pool.c

index d7f68e69b2ef0dda6ce612722bc18aa4ccc7a200..4151cdb22c729df5deeb3d39b7668bf976ae6e29 100644 (file)
@@ -352,6 +352,13 @@ struct pool_head *create_pool_from_reg(const char *name, struct pool_registratio
                alignment++;
        }
 
+       if (reg->type_align && alignment < reg->type_align) {
+               ha_alert("BUG in the code: at %s:%u, requested creation of pool '%s' aligned to %u "
+                        "while type requires alignment of %u! Please report to developers. Aborting.\n",
+                        reg->file, reg->line, name, alignment, reg->type_align);
+               return NULL;
+       }
+
        extra_mark = (pool_debugging & POOL_DBG_TAG) ? POOL_EXTRA_MARK : 0;
        extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
        extra = extra_mark + extra_caller;