From: Alvaro Neira Ayuso <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH 1/2] src: not create iterator with empty list
Date: Fri, 9 Jan 2015 13:47:40 +0100 [thread overview]
Message-ID: <1420807661-29751-1-git-send-email-alvaroneay@gmail.com> (raw)
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
next reply other threads:[~2015-01-09 12:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-09 12:47 Alvaro Neira Ayuso [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420807661-29751-1-git-send-email-alvaroneay@gmail.com \
--to=alvaroneay@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).