]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix gcc-10 build with -Werror=array-bounds and dl_list_for_each()
authorJouni Malinen <j@w1.fi>
Fri, 4 Dec 2020 11:45:03 +0000 (13:45 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 4 Dec 2020 11:59:37 +0000 (13:59 +0200)
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 <j@w1.fi>
src/utils/list.h
src/utils/os_unix.c

index 5298c26264d1fc1ce9b57d4769c7f730b392aff3..aa62c08811961f50b49b8e226ac9932d6aa7d39a 100644 (file)
@@ -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) \
index 6f0c1775666ff47c5ffffece08adb44326b11b4e..1de37204d710678c69c83cf5074834bf62a4ad78 100644 (file)
@@ -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)));