netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftnl PATCH 1/2] src: not create iterator with empty list
@ 2015-01-09 12:47 Alvaro Neira Ayuso
  2015-01-09 12:47 ` [libnftnl PATCH 2/2] ruleset: clean up the variable names in the xml/json parsing functions Alvaro Neira Ayuso
  2015-01-10 18:20 ` [libnftnl PATCH 1/2] src: not create iterator with empty list Pablo Neira Ayuso
  0 siblings, 2 replies; 6+ messages in thread
From: Alvaro Neira Ayuso @ 2015-01-09 12:47 UTC (permalink / raw)
  To: netfilter-devel

Now, 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>
---
 src/chain.c    |    3 +++
 src/rule.c     |    6 ++++++
 src/set.c      |    3 +++
 src/set_elem.c |    3 +++
 src/table.c    |    3 +++
 5 files changed, 18 insertions(+)

diff --git a/src/chain.c b/src/chain.c
index b67385e..e7de4ef 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -968,6 +968,9 @@ struct nft_chain_list_iter *nft_chain_list_iter_create(struct nft_chain_list *l)
 {
 	struct nft_chain_list_iter *iter;
 
+	if (nft_chain_list_is_empty(l))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_chain_list_iter));
 	if (iter == NULL)
 		return NULL;
diff --git a/src/rule.c b/src/rule.c
index c974f8b..f5a84f7 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1038,6 +1038,9 @@ struct nft_rule_expr_iter *nft_rule_expr_iter_create(struct nft_rule *r)
 {
 	struct nft_rule_expr_iter *iter;
 
+	if (list_empty(&r->expr_list))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_rule_expr_iter));
 	if (iter == NULL)
 		return NULL;
@@ -1147,6 +1150,9 @@ struct nft_rule_list_iter *nft_rule_list_iter_create(struct nft_rule_list *l)
 {
 	struct nft_rule_list_iter *iter;
 
+	if (nft_rule_list_is_empty(l))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_rule_list_iter));
 	if (iter == NULL)
 		return NULL;
diff --git a/src/set.c b/src/set.c
index 2385031..dee24a5 100644
--- a/src/set.c
+++ b/src/set.c
@@ -1015,6 +1015,9 @@ struct nft_set_list_iter *nft_set_list_iter_create(struct nft_set_list *l)
 {
 	struct nft_set_list_iter *iter;
 
+	if (nft_set_list_is_empty(l))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_set_list_iter));
 	if (iter == NULL)
 		return NULL;
diff --git a/src/set_elem.c b/src/set_elem.c
index 95f12bf..85c4519 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -684,6 +684,9 @@ struct nft_set_elems_iter *nft_set_elems_iter_create(struct nft_set *s)
 {
 	struct nft_set_elems_iter *iter;
 
+	if (list_empty(&s->element_list))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_set_elems_iter));
 	if (iter == NULL)
 		return NULL;
diff --git a/src/table.c b/src/table.c
index c93e6fb..544a8c3 100644
--- a/src/table.c
+++ b/src/table.c
@@ -539,6 +539,9 @@ struct nft_table_list_iter *nft_table_list_iter_create(struct nft_table_list *l)
 {
 	struct nft_table_list_iter *iter;
 
+	if (nft_table_list_is_empty(l))
+		return NULL;
+
 	iter = calloc(1, sizeof(struct nft_table_list_iter));
 	if (iter == NULL)
 		return NULL;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-10 18:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 12:47 [libnftnl PATCH 1/2] src: not create iterator with empty list Alvaro Neira Ayuso
2015-01-09 12:47 ` [libnftnl PATCH 2/2] ruleset: clean up the variable names in the xml/json parsing functions Alvaro Neira Ayuso
2015-01-10 18:23   ` Pablo Neira Ayuso
2015-01-10 18:20 ` [libnftnl PATCH 1/2] src: not create iterator with empty list Pablo Neira Ayuso
2015-01-10 18:26   ` Álvaro Neira Ayuso
2015-01-10 18:51     ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).