diff options
author | Alvaro Neira <alvaroneay@gmail.com> | 2015-01-12 14:46:14 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2015-01-15 13:04:46 +0100 |
commit | 1fc12719b6d878622e25825ef32615f281bb5e4d (patch) | |
tree | bdc7b855093bab8c26faf42118ad7dd628237084 /src/chain.c | |
parent | f9c72b4641bedf6f5b2fc4aefc42887e1884ed63 (diff) |
src: don't create iterator with empty list
Currently, we create iterator without test if the list is empty. If the
list is empty, we have a crash when we set up the current element. With
this patch, we test if the list is empty before to create the iterator.
If the list is empty the iterator return NULL.
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/chain.c')
-rw-r--r-- | src/chain.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/chain.c b/src/chain.c index b67385e..26ad14d 100644 --- a/src/chain.c +++ b/src/chain.c @@ -973,7 +973,10 @@ struct nft_chain_list_iter *nft_chain_list_iter_create(struct nft_chain_list *l) return NULL; iter->list = l; - iter->cur = list_entry(l->list.next, struct nft_chain, head); + if (nft_chain_list_is_empty(l)) + iter->cur = NULL; + else + iter->cur = list_entry(l->list.next, struct nft_chain, head); return iter; } @@ -983,6 +986,9 @@ struct nft_chain *nft_chain_list_iter_next(struct nft_chain_list_iter *iter) { struct nft_chain *r = iter->cur; + if (r == NULL) + return NULL; + /* get next chain, if any */ iter->cur = list_entry(iter->cur->head.next, struct nft_chain, head); if (&iter->cur->head == iter->list->list.next) |