From 3b6b3ae5813329fa69d86a553ff263bc17e8b41b Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 23 Feb 2019 12:07:21 +0200 Subject: [PATCH] Modify dl_list_for_each() to not use unaligned access with WPA_TRACE 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 --- src/utils/list.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/list.h b/src/utils/list.h index ee2f48569..85aa5e39c 100644 --- a/src/utils/list.h +++ b/src/utils/list.h @@ -1,6 +1,6 @@ /* * Doubly-linked list - * Copyright (c) 2009, Jouni Malinen + * Copyright (c) 2009-2019, Jouni Malinen * * 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) \