From 28054c8d5cbcfdea460baedc037cb19260389baa Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 19 Feb 2024 21:13:59 +1100 Subject: [PATCH 1/2] config: use -Wno-format-truncation globally -Wformat-truncation looks for places where the return code of snprintf() is unchecked and the provided buffer might be too short. This is based on a heuristic that can change between compiler versions. It has been seen to get this wrong in ddt_object_name(), leading to DDT_NAMELEN being increased somewhat arbitrarily. There's no good reason to have this warning enabled, so here we disable it everywhere. Truncation may be undesirable, but snprintf() is guaranteed to emit a trailing null, so at worst we get a short string, not a buffer overrun. Signed-off-by: Rob Norris Sponsored-by: https://despairlabs.com/sponsor/ --- cmd/Makefile.am | 2 -- config/Rules.am | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 6d6de4adb42a..2bd9d039f20e 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -39,8 +39,6 @@ zhack_LDADD = \ ztest_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) -# Get rid of compiler warning for unchecked truncating snprintfs on gcc 7.1.1 -ztest_CFLAGS += $(NO_FORMAT_TRUNCATION) ztest_CPPFLAGS = $(AM_CPPFLAGS) $(FORCEDEBUG_CPPFLAGS) sbin_PROGRAMS += ztest diff --git a/config/Rules.am b/config/Rules.am index 2e463ae6083a..30c5f353cd23 100644 --- a/config/Rules.am +++ b/config/Rules.am @@ -21,7 +21,9 @@ AM_CFLAGS += $(IMPLICIT_FALLTHROUGH) AM_CFLAGS += $(DEBUG_CFLAGS) AM_CFLAGS += $(ASAN_CFLAGS) AM_CFLAGS += $(UBSAN_CFLAGS) -AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) $(NO_FORMAT_ZERO_LENGTH) +AM_CFLAGS += $(CODE_COVERAGE_CFLAGS) +AM_CFLAGS += $(NO_FORMAT_ZERO_LENGTH) +AM_CFLAGS += $(NO_FORMAT_TRUNCATION) if BUILD_FREEBSD AM_CFLAGS += -fPIC -Werror -Wno-unknown-pragmas -Wno-enum-conversion AM_CFLAGS += -include $(top_srcdir)/include/os/freebsd/spl/sys/ccompile.h From 220c77210e5e0df536f4c46d0f808e6e4c9fd73b Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 19 Feb 2024 21:19:32 +1100 Subject: [PATCH 2/2] ddt: reduce DDT_NAMELEN This is the buffer size passed to ddt_object_name(), to expand the DMU_POOL_DDT format. That format inserts the table checksum, class and type names, which as I write this are max 6, 9 and 3, respectively. Signed-off-by: Rob Norris Sponsored-by: https://despairlabs.com/sponsor/ --- include/sys/ddt_impl.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/sys/ddt_impl.h b/include/sys/ddt_impl.h index d6693658885b..52b927b7519d 100644 --- a/include/sys/ddt_impl.h +++ b/include/sys/ddt_impl.h @@ -66,7 +66,12 @@ extern void ddt_stat_update(ddt_t *ddt, ddt_entry_t *dde, uint64_t neg); * outside of the DDT implementation proper, and if you do, consider moving * them up. */ -#define DDT_NAMELEN 110 + +/* + * Enough room to expand DMU_POOL_DDT format for all possible DDT + * checksum/class/type combinations. + */ +#define DDT_NAMELEN 32 extern uint64_t ddt_phys_total_refcnt(const ddt_entry_t *dde);