]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use a non-atomic counter when passing to stats dumper
authorAydın Mercan <aydin@isc.org>
Mon, 11 Dec 2023 10:50:45 +0000 (13:50 +0300)
committerAydın Mercan <aydin@isc.org>
Wed, 3 Jan 2024 17:36:35 +0000 (20:36 +0300)
(cherry picked from commit bb96142a17a8b65defbc9fcc66679d114cbb2576)

lib/isc/stats.c

index 2e3fd3f47febfd1bf8276d012fcf0515e33047e1..86d483304212deb9facae33e63ea6efb4cab048c 100644 (file)
 
 typedef atomic_int_fast64_t isc__atomic_statcounter_t;
 
+/*
+ * Statistics are counted with an atomic int_fast64_t but exported to functions
+ * taking int64_t (isc_stats_dumper_t). A 128-bit native and fast architecture
+ * doesn't exist in reality so these two are the same thing in practise.
+ * However, a silent truncation happening silently in the future is still not
+ * acceptable.
+ */
+STATIC_ASSERT(sizeof(isc__atomic_statcounter_t) <= sizeof(int64_t),
+             "Exported statistics must fit into the statistic counter size");
+
 struct isc_stats {
        unsigned int magic;
        isc_mem_t *mctx;
@@ -125,7 +135,7 @@ isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn, void *arg,
        REQUIRE(ISC_STATS_VALID(stats));
 
        for (i = 0; i < stats->ncounters; i++) {
-               isc__atomic_statcounter_t counter = atomic_load_acquire(&stats->counters[i]);
+               int_fast64_t counter = atomic_load_acquire(&stats->counters[i]);
                if ((options & ISC_STATSDUMP_VERBOSE) == 0 && counter == 0) {
                        continue;
                }