]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Assert if statistics counter underflows in the developer mode
authorOndřej Surý <ondrej@isc.org>
Mon, 17 Jan 2022 11:39:56 +0000 (12:39 +0100)
committerPetr Špaček <pspacek@isc.org>
Thu, 10 Feb 2022 16:18:09 +0000 (17:18 +0100)
There are reported occurences where the statitic counters underflows and
starts reporting non-sense.

Add a check for the underflow, when ``named`` is compiled in the
developer mode.

configure.ac
lib/isc/stats.c

index 08866a0101d75911edd7bb158f645ae534b7ed4e..9138636dddaa221a1864b9e78a6fee9d7984c2be 100644 (file)
@@ -148,7 +148,7 @@ AC_ARG_ENABLE([developer],
 
 AS_IF([test "$enable_developer" = "yes"],
       [DEVELOPER_MODE=yes
-       STD_CPPFLAGS="$STD_CPPFLAGS -DISC_MEM_DEFAULTFILL=1 -DISC_MEM_TRACKLINES=1 -DISC_LIST_CHECKINIT=1"
+       STD_CPPFLAGS="$STD_CPPFLAGS -DISC_MEM_DEFAULTFILL=1 -DISC_MEM_TRACKLINES=1 -DISC_LIST_CHECKINIT=1 -DISC_STATS_CHECKUNDERFLOW=1"
        test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
        test "${enable_querytrace+set}" = set || enable_querytrace=yes
        test "${with_cmocka+set}" = set || with_cmocka=yes
index 3e4676c2aca710806e395a39026926559beff8c6..756733ed5109164381d48b93e1794b82dd50091f 100644 (file)
@@ -114,7 +114,11 @@ void
 isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) {
        REQUIRE(ISC_STATS_VALID(stats));
        REQUIRE(counter < stats->ncounters);
+#if ISC_STATS_CHECKUNDERFLOW
+       REQUIRE(atomic_fetch_sub_release(&stats->counters[counter], 1) > 0);
+#else
        atomic_fetch_sub_release(&stats->counters[counter], 1);
+#endif
 }
 
 void