From bd2b75a21e20bcf377d6bc2e30517d5c9072c287 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 16 Oct 2019 08:51:43 -0400 Subject: [PATCH] nhrpd: be more careful with linked lists NHRPD has its own linked-list implementation, and one of the apis is a little free and easy with pointers. Also be safer with one list iteration operation. Signed-off-by: Mark Stapp --- nhrpd/list.h | 3 ++- nhrpd/nhrpd.h | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nhrpd/list.h b/nhrpd/list.h index ee7f1c4403..590d92560c 100644 --- a/nhrpd/list.h +++ b/nhrpd/list.h @@ -199,7 +199,8 @@ static inline int list_empty(const struct list_head *n) #define list_for_each_entry_safe(pos, n, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ + n = (&pos->member != (head) ? \ + list_entry(pos->member.next, typeof(*pos), member) : NULL); \ &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h index 50746d9ad5..ad38cad83b 100644 --- a/nhrpd/nhrpd.h +++ b/nhrpd/nhrpd.h @@ -76,8 +76,10 @@ static inline void notifier_del(struct notifier_block *n) static inline void notifier_call(struct notifier_list *l, int cmd) { struct notifier_block *n, *nn; - list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) - n->action(n, cmd); + list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) { + if (n) + n->action(n, cmd); + } } static inline int notifier_active(struct notifier_list *l) -- 2.39.5