]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle ISC_MEM_DEFAULTFILL consistently
authorMichał Kępień <michal@isc.org>
Fri, 15 Jul 2022 08:23:03 +0000 (10:23 +0200)
committerMichał Kępień <michal@isc.org>
Fri, 15 Jul 2022 08:45:34 +0000 (10:45 +0200)
Contrary to what the documentation states, memory filling is only
enabled by --enable-developer (or by setting -DISC_MEM_DEFAULTFILL=1) if
the internal memory allocator is used.  However, the internal memory
allocator is disabled by default, so just using the --enable-developer
build-time option does not enable memory filling (passing "-M fill" on
the named command line is necessary to actually enable it).  As memory
filling is a useful tool for troubleshooting certain types of bugs, it
should also be enabled by --enable-developer when the system allocator
is used.

Furthermore, memory-related preprocessor macros are handled in two
distinct locations: lib/isc/include/isc/mem.h and bin/named/main.c.
This makes the logic hard to follow.

Move all code handling the ISC_MEM_DEFAULTFILL preprocessor macro to
lib/isc/include/isc/mem.h, ensuring memory filling is enabled by the
--enable-developer build-time switch, no matter which memory allocator
is used.

bin/named/main.c
lib/isc/include/isc/mem.h

index 4de10c89eb0d7f5f80be682abfda81143086d8db..db98f133b50c8406e6924b646b5281fb16061017 100644 (file)
@@ -1529,15 +1529,6 @@ main(int argc, char *argv[]) {
        pk11_result_register();
 #endif /* if USE_PKCS11 */
 
-#if !ISC_MEM_DEFAULTFILL
-       /*
-        * Update the default flags to remove ISC_MEMFLAG_FILL
-        * before we parse the command line. If disabled here,
-        * it can be turned back on with -M fill.
-        */
-       isc_mem_defaultflags &= ~ISC_MEMFLAG_FILL;
-#endif /* if !ISC_MEM_DEFAULTFILL */
-
        parse_command_line(argc, argv);
 
 #ifdef ENABLE_AFL
index 04c4a0297fcee63b7446769541ef6d7e7e70a858..1542edd76e5d080d98cc719af4308bd4fe4d7b7c 100644 (file)
@@ -130,10 +130,26 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
 #define ISC_MEMFLAG_FILL \
        0x00000004 /* fill with pattern after alloc and frees */
 
+/*%
+ * Define ISC_MEM_DEFAULTFILL=1 to turn filling the memory with pattern
+ * after alloc and free.
+ */
 #if !ISC_MEM_USE_INTERNAL_MALLOC
+
+#if ISC_MEM_DEFAULTFILL
+#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_FILL
+#else /* if ISC_MEM_DEFAULTFILL */
 #define ISC_MEMFLAG_DEFAULT 0
+#endif /* if ISC_MEM_DEFAULTFILL */
+
 #else /* if !ISC_MEM_USE_INTERNAL_MALLOC */
+
+#if ISC_MEM_DEFAULTFILL
 #define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL | ISC_MEMFLAG_FILL
+#else /* if ISC_MEM_DEFAULTFILL */
+#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL
+#endif /* if ISC_MEM_DEFAULTFILL */
+
 #endif /* if !ISC_MEM_USE_INTERNAL_MALLOC */
 
 /*%