From bba926350a0e28fa181af7caee24a11619ad10fc Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 4 Dec 2020 13:45:03 +0200 Subject: [PATCH] Fix gcc-10 build with -Werror=array-bounds and dl_list_for_each() The earlier workaround for UBSAN issues in commit 3b6b3ae58133 ("Modify dl_list_for_each() to not use unaligned access with WPA_TRACE") ended up using a construction in which the type cast to the containing structure was compared instead of the struct dl_list pointers. While that worked around the UBSAN issue, it resulted in a comparison that gcc-10 interprets as being out of bounds for struct dl_list (which it obviously is since this is to find the start of the containing structure). Revert that workaround and instead, mark the struct dl_list used within struct os_alloc_trace to have matching 16 octet alignment as the containing structure. This is also restoring consistent design for dl_list_for_each*(). Signed-off-by: Jouni Malinen --- src/utils/list.h | 4 ++-- src/utils/os_unix.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/list.h b/src/utils/list.h index 5298c2626..aa62c0881 100644 --- a/src/utils/list.h +++ b/src/utils/list.h @@ -76,8 +76,8 @@ static inline unsigned int dl_list_len(const struct dl_list *list) dl_list_entry((list)->prev, type, member)) #define dl_list_for_each(item, list, type, member) \ - for (item = dl_list_first((list), type, member); \ - item && item != dl_list_entry((list), type, member); \ + for (item = dl_list_entry((list)->next, type, member); \ + &item->member != (list); \ item = dl_list_entry(item->member.next, type, member)) #define dl_list_for_each_safe(item, n, list, type, member) \ diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 6f0c17756..1de37204d 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -39,7 +39,7 @@ static struct dl_list alloc_list = DL_LIST_HEAD_INIT(alloc_list); struct os_alloc_trace { unsigned int magic; - struct dl_list list; + struct dl_list list __attribute__((aligned(16))); size_t len; WPA_TRACE_INFO } __attribute__((aligned(16)));