]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stats-file: add some BUG_ON() guards to ensure exported structs are not chang...
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Sep 2025 14:23:33 +0000 (16:23 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Sep 2025 14:29:55 +0000 (16:29 +0200)
Add two BUG_ON() in shm_stats_file_prepare() which will trigger if
exported structures (shm_stats_file_hdr and shm_stats_file_object) change
in size, because it means that they will become incompatible with older
versions and thus precautions should be taken by the developer to ensure
compatibility with olders versions, or at least detect incompatible
versions by changing the version number to prevent bugs resulting
from inconsistent mapping between versions. The BUG_ON() may be
safely adjusted then.

Please note that it doesn't protect against accidental struct member
re-ordering if the resulting struct size is equal..

src/stats-file.c

index e9050e89a1f699694d968a593153d0b8f7aa8e61..4f74c3062c7e2e3383557d706ca971c047e4bbff 100644 (file)
@@ -802,6 +802,13 @@ int shm_stats_file_prepare(void)
        int slot;
        int objects;
 
+       BUG_ON(sizeof(struct shm_stats_file_hdr) != 672, "shm_stats_file_hdr struct size changed, "
+              "it is part of the exported API: ensure all precautions were taken (ie: shm_stats_file "
+              "version change) before adjusting this");
+       BUG_ON(sizeof(struct shm_stats_file_object) != 544, "shm_stats_file_object struct size changed, "
+              "is is part of the exported API: ensure all precautions were taken (ie: shm_stats_file "
+              "version change) before adjusting this");
+
        /* do nothing if master process or shm_stats_file not configured */
        if (master || !global.shm_stats_file)
                return ERR_NONE;