BUILD: pools: silence build warnings with DEBUG_MEMORY_POOLS and DEBUG_UAF
authorWilly Tarreau <w@1wt.eu>
Sat, 14 Mar 2020 10:08:16 +0000 (11:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 14 Mar 2020 10:10:21 +0000 (11:10 +0100)
With these debug options we still get these warnings:

include/common/memory.h:501:23: warning: null pointer dereference [-Wnull-dereference]
    *(volatile int *)0 = 0;
    ~~~~~~~~~~~~~~~~~~~^~~
include/common/memory.h:460:22: warning: null pointer dereference [-Wnull-dereference]
   *(volatile int *)0 = 0;
   ~~~~~~~~~~~~~~~~~~~^~~

These are purposely there to crash the process at specific locations.
But the annoying warnings do not help with debugging and they are not
even reliable as the compiler may decide to optimize them away. Let's
pass the pointer through DISGUISE() to avoid this.

include/common/memory.h

index 5071989..5433a73 100644 (file)
@@ -335,7 +335,7 @@ static inline void pool_free(struct pool_head *pool, void *ptr)
 #ifdef DEBUG_MEMORY_POOLS
                /* we'll get late corruption if we refill to the wrong pool or double-free */
                if (*POOL_LINK(pool, ptr) != (void *)pool)
-                       *(volatile int *)0 = 0;
+                       *DISGUISE((volatile int *)0) = 0;
 #endif
                if (mem_poison_byte >= 0)
                        memset(ptr, mem_poison_byte, pool->size);
@@ -457,7 +457,7 @@ static inline void pool_free_area(void *area, size_t size)
        size_t pad = (4096 - size) & 0xFF0;
 
        if (pad >= sizeof(void *) && *(void **)(area - sizeof(void *)) != area)
-               *(volatile int *)0 = 0;
+               *DISGUISE((volatile int *)0) = 0;
 
        thread_harmless_now();
        munmap(area - pad, (size + 4095) & -4096);
@@ -498,7 +498,7 @@ static inline void pool_free(struct pool_head *pool, void *ptr)
 #ifdef DEBUG_MEMORY_POOLS
                /* we'll get late corruption if we refill to the wrong pool or double-free */
                if (*POOL_LINK(pool, ptr) != (void *)pool)
-                       *(volatile int *)0 = 0;
+                       *DISGUISE((volatile int *)0) = 0;
 #endif
 
 #ifndef DEBUG_UAF /* normal pool behaviour */