[PATCH 2/2 libnfntl] Fix nftnl_*_get to set data_len

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All getters must set the output parameter 'data_len'

Signed-off-by: Carlos Falgueras García <carlosfg@xxxxxxxxxx>
---
 src/chain.c       | 3 +++
 src/expr.c        | 1 +
 src/expr/dynset.c | 3 +++
 src/expr/lookup.c | 3 +++
 src/gen.c         | 1 +
 src/rule.c        | 2 ++
 src/set.c         | 2 ++
 src/set_elem.c    | 6 ++++++
 src/table.c       | 1 +
 9 files changed, 22 insertions(+)

diff --git a/src/chain.c b/src/chain.c
index cab64b5..ccf0f92 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -272,8 +272,10 @@ const void *nftnl_chain_get_data(const struct nftnl_chain *c, uint16_t attr,
 
 	switch(attr) {
 	case NFTNL_CHAIN_NAME:
+		*data_len = strlen(c->name);
 		return c->name;
 	case NFTNL_CHAIN_TABLE:
+		*data_len = strlen(c->table);
 		return c->table;
 	case NFTNL_CHAIN_HOOKNUM:
 		*data_len = sizeof(uint32_t);
@@ -303,6 +305,7 @@ const void *nftnl_chain_get_data(const struct nftnl_chain *c, uint16_t attr,
 		*data_len = sizeof(uint32_t);
 		return c->type;
 	case NFTNL_CHAIN_DEV:
+		*data_len = strlen(c->dev);
 		return c->dev;
 	}
 	return NULL;
diff --git a/src/expr.c b/src/expr.c
index f802725..06afcd3 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -119,6 +119,7 @@ const void *nftnl_expr_get(const struct nftnl_expr *expr,
 
 	switch(type) {
 	case NFTNL_EXPR_NAME:
+		*data_len = strlen(expr->ops->name);
 		ret = expr->ops->name;
 		break;
 	default:
diff --git a/src/expr/dynset.c b/src/expr/dynset.c
index 0404359..6bf360e 100644
--- a/src/expr/dynset.c
+++ b/src/expr/dynset.c
@@ -88,10 +88,13 @@ nftnl_expr_dynset_get(const struct nftnl_expr *e, uint16_t type,
 		*data_len = sizeof(dynset->timeout);
 		return &dynset->timeout;
 	case NFTNL_EXPR_DYNSET_SET_NAME:
+		*data_len = strlen(dynset->set_name);
 		return dynset->set_name;
 	case NFTNL_EXPR_DYNSET_SET_ID:
+		*data_len = sizeof(dynset->set_id);
 		return &dynset->set_id;
 	case NFTNL_EXPR_DYNSET_EXPR:
+		*data_len = 0;
 		return dynset->expr;
 	}
 	return NULL;
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 7f68f74..54d19d6 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -73,10 +73,13 @@ nftnl_expr_lookup_get(const struct nftnl_expr *e, uint16_t type,
 		*data_len = sizeof(lookup->dreg);
 		return &lookup->dreg;
 	case NFTNL_EXPR_LOOKUP_SET:
+		*data_len = strlen(lookup->set_name);
 		return lookup->set_name;
 	case NFTNL_EXPR_LOOKUP_SET_ID:
+		*data_len = sizeof(lookup->set_id);
 		return &lookup->set_id;
 	case NFTNL_EXPR_LOOKUP_FLAGS:
+		*data_len = sizeof(lookup->flags);
 		return &lookup->flags;
 	}
 	return NULL;
diff --git a/src/gen.c b/src/gen.c
index 37a9049..c69d2f8 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -100,6 +100,7 @@ const void *nftnl_gen_get_data(const struct nftnl_gen *gen, uint16_t attr,
 
 	switch(attr) {
 	case NFTNL_GEN_ID:
+		*data_len = sizeof(gen->id);
 		return &gen->id;
 	}
 	return NULL;
diff --git a/src/rule.c b/src/rule.c
index 2b23c8e..bf72595 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -213,8 +213,10 @@ const void *nftnl_rule_get_data(const struct nftnl_rule *r, uint16_t attr,
 		*data_len = sizeof(uint32_t);
 		return &r->family;
 	case NFTNL_RULE_TABLE:
+		*data_len = strlen(r->table);
 		return r->table;
 	case NFTNL_RULE_CHAIN:
+		*data_len = strlen(r->chain);
 		return r->chain;
 	case NFTNL_RULE_HANDLE:
 		*data_len = sizeof(uint64_t);
diff --git a/src/set.c b/src/set.c
index e48ff78..f728373 100644
--- a/src/set.c
+++ b/src/set.c
@@ -215,8 +215,10 @@ const void *nftnl_set_get_data(const struct nftnl_set *s, uint16_t attr,
 
 	switch(attr) {
 	case NFTNL_SET_TABLE:
+		*data_len = strlen(s->table);
 		return s->table;
 	case NFTNL_SET_NAME:
+		*data_len = strlen(s->name);
 		return s->name;
 	case NFTNL_SET_FLAGS:
 		*data_len = sizeof(uint32_t);
diff --git a/src/set_elem.c b/src/set_elem.c
index 40b5bfe..2056209 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -160,25 +160,31 @@ const void *nftnl_set_elem_get(struct nftnl_set_elem *s, uint16_t attr, uint32_t
 
 	switch(attr) {
 	case NFTNL_SET_ELEM_FLAGS:
+		*data_len = sizeof(s->set_elem_flags);
 		return &s->set_elem_flags;
 	case NFTNL_SET_ELEM_KEY:	/* NFTA_SET_ELEM_KEY */
 		*data_len = s->key.len;
 		return &s->key.val;
 	case NFTNL_SET_ELEM_VERDICT:	/* NFTA_SET_ELEM_DATA */
+		*data_len = sizeof(s->data.verdict);
 		return &s->data.verdict;
 	case NFTNL_SET_ELEM_CHAIN:	/* NFTA_SET_ELEM_DATA */
+		*data_len = strlen(s->data.chain);
 		return s->data.chain;
 	case NFTNL_SET_ELEM_DATA:	/* NFTA_SET_ELEM_DATA */
 		*data_len = s->data.len;
 		return &s->data.val;
 	case NFTNL_SET_ELEM_TIMEOUT:	/* NFTA_SET_ELEM_TIMEOUT */
+		*data_len = sizeof(s->timeout);
 		return &s->timeout;
 	case NFTNL_SET_ELEM_EXPIRATION:	/* NFTA_SET_ELEM_EXPIRATION */
+		*data_len = sizeof(s->expiration);
 		return &s->expiration;
 	case NFTNL_SET_ELEM_USERDATA:
 		*data_len = s->user.len;
 		return s->user.data;
 	case NFTNL_SET_ELEM_EXPR:
+		*data_len = 0;
 		return s->expr;
 	}
 	return NULL;
diff --git a/src/table.c b/src/table.c
index 966b923..78e27bc 100644
--- a/src/table.c
+++ b/src/table.c
@@ -143,6 +143,7 @@ const void *nftnl_table_get_data(const struct nftnl_table *t, uint16_t attr,
 
 	switch(attr) {
 	case NFTNL_TABLE_NAME:
+		*data_len = strlen(t->name);
 		return t->name;
 	case NFTNL_TABLE_FLAGS:
 		*data_len = sizeof(uint32_t);
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux