]> git.puffer.fish Git - mirror/frr.git/commitdiff
nhrpd: be more careful with linked lists
authorMark Stapp <mjs@voltanet.io>
Wed, 16 Oct 2019 12:51:43 +0000 (08:51 -0400)
committerDavid Lamparter <equinox@diac24.net>
Wed, 6 May 2020 16:23:55 +0000 (18:23 +0200)
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 <mjs@voltanet.io>
nhrpd/list.h
nhrpd/nhrpd.h

index ee7f1c4403f4e3624fcf37d5b8d5f807a2be0ae1..590d92560c3aec2526df7073e194302e36560adc 100644 (file)
@@ -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))
 
index 670c9f4f18c6878d1e7b7a6d86b925d4310e0bea..d09a6f5970ba52b2478b94a1b210d838eec7d041 100644 (file)
@@ -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)