From: Andrew Deason Date: Thu, 20 Dec 2018 20:29:47 +0000 (-0600) Subject: rx: Statically check rx_statisticsAtomic size X-Git-Tag: openafs-devel-1_9_0~389 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=b2475c11f4d430402a82cb5b018dbccdaa0dccd8;hp=fa3ce81178b23ee2d96f4e496484c23ed0ce7bfc rx: Statically check rx_statisticsAtomic size Currently, rx_GetStatistics assumes that struct rx_statistics and rx_statisticsAtomic have the same size (we just memcpy between them). However, this is never checked, and rx_statistics contains many 'int' fields where rx_statisticsAtomic has rx_atomic_t fields. If these are not the same size, our rx stats will silently break, so add a static assert to make sure they are the same size. Change-Id: I889867f4a85530c30dd15d32d1822144ea128a95 Reviewed-on: https://gerrit.openafs.org/13414 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- diff --git a/src/rx/rx_stats.c b/src/rx/rx_stats.c index 2693137..2daa548 100644 --- a/src/rx/rx_stats.c +++ b/src/rx/rx_stats.c @@ -33,8 +33,8 @@ #if !defined(KERNEL) #include -#include #endif +#include #ifdef KERNEL /* no kmutex, no atomic emulation...*/ @@ -67,7 +67,9 @@ struct rx_statisticsAtomic rx_stats; struct rx_statistics * rx_GetStatistics(void) { struct rx_statistics *stats = rxi_Alloc(sizeof(struct rx_statistics)); + MUTEX_ENTER(&rx_stats_mutex); + opr_StaticAssert(sizeof(*stats) == sizeof(rx_stats)); memcpy(stats, &rx_stats, sizeof(struct rx_statistics)); MUTEX_EXIT(&rx_stats_mutex);