From 0893b5fb79cef78ac10d25326f85220a86311edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 17 Jan 2022 12:39:56 +0100 Subject: [PATCH] Assert if statistics counter underflows in the developer mode 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 | 2 +- lib/isc/stats.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 08866a0101..9138636ddd 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/lib/isc/stats.c b/lib/isc/stats.c index 3e4676c2ac..756733ed51 100644 --- a/lib/isc/stats.c +++ b/lib/isc/stats.c @@ -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