From: Aurelien DARRAGON Date: Wed, 3 Sep 2025 14:23:33 +0000 (+0200) Subject: MEDIUM: stats-file: add some BUG_ON() guards to ensure exported structs are not chang... X-Git-Tag: v3.3-dev8~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f32bc8f0a445341e3f88c56303d92b2378c7920f;p=thirdparty%2Fhaproxy.git MEDIUM: stats-file: add some BUG_ON() guards to ensure exported structs are not changed by accident 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.. --- diff --git a/src/stats-file.c b/src/stats-file.c index e9050e89a..4f74c3062 100644 --- a/src/stats-file.c +++ b/src/stats-file.c @@ -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;