]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Modify dl_list_for_each() to not use unaligned access with WPA_TRACE
authorJouni Malinen <j@w1.fi>
Sat, 23 Feb 2019 10:07:21 +0000 (12:07 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 25 Feb 2019 17:42:34 +0000 (19:42 +0200)
UBSan testing with WPA_TRACE=y ended up hitting an unaligned access for
struct os_alloc_trace in os_program_deinit() because of the
dl_list_for_each() design that looked like dereferencing the member
element of the list head which is something that does not exist.

Get the first entry from the list using dl_list_first() so that the
empty list special case is covefred and compare item pointers instead of
struct dl_list pointers to check whether the end of the loop has been
reached.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/list.h

index ee2f4856950f1e9025d93595d1893e539dc667a3..85aa5e39cfe16d6cb78caa4723948e6a26b0302c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Doubly-linked list
- * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2009-2019, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -76,8 +76,8 @@ static inline unsigned int dl_list_len(struct dl_list *list)
         dl_list_entry((list)->prev, type, member))
 
 #define dl_list_for_each(item, list, type, member) \
-       for (item = dl_list_entry((list)->next, type, member); \
-            &item->member != (list); \
+       for (item = dl_list_first((list), type, member); \
+            item && item != dl_list_entry((list), type, member); \
             item = dl_list_entry(item->member.next, type, member))
 
 #define dl_list_for_each_safe(item, n, list, type, member) \