mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-11 00:42:46 +02:00
DEBUG: list: add DEBUG_LIST to purposely corrupt list heads after delete
LIST_DELETE doesn't affect the previous pointers of the stored element. This can sometimes hide bugs when such a pointer is reused by accident in a LIST_NEXT() or equivalent after having been detached for example, or ia another LIST_DELETE is performed again, something that LIST_DEL_INIT() is immune to. By compiling with -DDEBUG_LIST, we'll replace a freshly detached list element with two invalid pointers that will cause a crash in case of accidental misuse. It's not enabled by default.
This commit is contained in:
@@ -72,7 +72,12 @@
|
||||
} while (0)
|
||||
|
||||
/* removes an element from a list and returns it */
|
||||
#if defined(DEBUG_LIST)
|
||||
/* purposely corrupt the detached element to detect use-after-delete */
|
||||
#define LIST_DELETE(el) ({ typeof(el) __ret = (el); (el)->n->p = (el)->p; (el)->p->n = (el)->n; *(__ret) = (struct list)ILH; (__ret);})
|
||||
#else
|
||||
#define LIST_DELETE(el) ({ typeof(el) __ret = (el); (el)->n->p = (el)->p; (el)->p->n = (el)->n; (__ret); })
|
||||
#endif
|
||||
|
||||
/* removes an element from a list, initializes it and returns it.
|
||||
* This is faster than LIST_DELETE+LIST_INIT as we avoid reloading the pointers.
|
||||
|
||||
Reference in New Issue
Block a user