set: Fix nftnl_set_set_str
PATCH 1/1 set: Fix nftnl_set_set_str
We need the string length
--- src/set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/set.c +1 -1
@@ -203,7 +203,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str)); }EXPORT_SYMBOL_ALIAS (nftnl_set_set_str, nft_set_attr_set_str);
Signature · 6 lines
2.8.3 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Carlos Falgueras García
We need the string length
Signed-off-by Carlos Falgueras García <[email protected]>--- src/set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/set.c +0
-0
src/set.c EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64); · line 208
Quoted 7 lines
src/set.c +1
-1@@ -203,7 +203,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str)); }EXPORT_SYMBOL_ALIAS (nftnl_set_set_str, nft_set_attr_set_str);
This bug has gone unnoticed because all tests check if the set attribute was equal to the parsed one, but not check if it was really set. If you try to set an string but it fail, the test compares two empty strings and says that it is correct.
Maybe we can impove the tests if it checks too if the gotten attribute is equal to the set one. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerQuoted 12 lines · Carlos Falgueras García
We need the string length
Signed-off-by Carlos Falgueras García <[email protected]>--- src/set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/set.c +0
-0
src/set.c EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64); · line 206
Quoted 5 lines
src/set.c +1
-1@@ -203,7 +203,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str));
I think this should be strlen(str) + 1 so we make sure the string is nul-terminated.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 set: Fix nftnl_set_set_str
We need the string length
--- src/set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/set.c +1 -1
@@ -190,7 +190,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_set_str, nft_set_attr_set_str);
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 Fix string length calculations
In reply to Pablo Neira AyusoThese lengths must be one character longer to take account the null character
--- src/chain.c | 2 +- src/rule.c | 2 +- src/set_elem.c | 2 +- src/table.c | 2 +- src/trace.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)
src/chain.c +1 -1
@@ -260,7 +260,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_chain_set_u8, nft_chain_attr_set_u8);int nftnl_chain_set_str (struct nftnl_chain *c,uint16_t attr,const char *str) { -return nftnl_chain_set_data (c, attr, str,strlen (str)); +return nftnl_chain_set_data (c, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_chain_set_str, nft_chain_attr_set_str);
src/rule.c +1 -1
@@ -198,7 +198,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_rule_set_u64, nft_rule_attr_set_u64);int nftnl_rule_set_str (struct nftnl_rule *r,uint16_t attr,const char *str) { -return nftnl_rule_set_data (r, attr, str,strlen (str)); +return nftnl_rule_set_data (r, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_rule_set_str, nft_rule_attr_set_str);
src/set_elem.c +1 -1
@@ -149,7 +149,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_elem_set_u64, nft_set_elem_attr_set_u64);int nftnl_set_elem_set_str (struct nftnl_set_elem *s,uint16_t attr,const char *str) { -return nftnl_set_elem_set (s, attr, str,strlen (str)); +return nftnl_set_elem_set (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_elem_set_str, nft_set_elem_attr_set_str);
src/table.c +1 -1
@@ -131,7 +131,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_table_set_u8, nft_table_attr_set_u8);int nftnl_table_set_str (struct nftnl_table *t,uint16_t attr,const char *str) { -return nftnl_table_set_data (t, attr, str,0 ); +return nftnl_table_set_data (t, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_table_set_str, nft_table_attr_set_str);
src/trace.c +3 -3
@@ -165,13 +165,13 @@ const void *nftnl_trace_get_data(const struct nftnl_trace *trace, *data_len =sizeof (uint32_t );return &trace->type;case NFTNL_TRACE_CHAIN : - *data_len =strlen (trace->chain); + *data_len =strlen (trace->chain) +1 ;return trace->chain;case NFTNL_TRACE_TABLE : - *data_len =strlen (trace->table); + *data_len =strlen (trace->table) +1 ;return trace->table;case NFTNL_TRACE_JUMP_TARGET : - *data_len =strlen (trace->jump_target); + *data_len =strlen (trace->jump_target) +1 ;return trace->jump_target;case NFTNL_TRACE_TRANSPORT_HEADER : *data_len = trace->th.len;
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH libnftnl] Fix string length calculations
Quoted 2 lines · Carlos Falgueras García
These lengths must be one character longer to take account the null character
Please, place the change for src/set.c in this patch so I only need to apply one patch.
Another comment below.
Quoted 72 lines
Signed-off-by Carlos Falgueras García <[email protected]>--- src/chain.c | 2 +- src/rule.c | 2 +- src/set_elem.c | 2 +- src/table.c | 2 +- src/trace.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)src/chain.c +1
-1@@ -260,7 +260,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_chain_set_u8, nft_chain_attr_set_u8);int nftnl_chain_set_str (struct nftnl_chain *c,uint16_t attr,const char *str) { -return nftnl_chain_set_data (c, attr, str,strlen (str)); +return nftnl_chain_set_data (c, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_chain_set_str, nft_chain_attr_set_str);src/rule.c +1
-1@@ -198,7 +198,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_rule_set_u64, nft_rule_attr_set_u64);int nftnl_rule_set_str (struct nftnl_rule *r,uint16_t attr,const char *str) { -return nftnl_rule_set_data (r, attr, str,strlen (str)); +return nftnl_rule_set_data (r, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_rule_set_str, nft_rule_attr_set_str);src/set_elem.c +1
-1@@ -149,7 +149,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_elem_set_u64, nft_set_elem_attr_set_u64);int nftnl_set_elem_set_str (struct nftnl_set_elem *s,uint16_t attr,const char *str) { -return nftnl_set_elem_set (s, attr, str,strlen (str)); +return nftnl_set_elem_set (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_elem_set_str, nft_set_elem_attr_set_str);src/table.c +1
-1@@ -131,7 +131,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_table_set_u8, nft_table_attr_set_u8);int nftnl_table_set_str (struct nftnl_table *t,uint16_t attr,const char *str) { -return nftnl_table_set_data (t, attr, str,0 ); +return nftnl_table_set_data (t, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_table_set_str, nft_table_attr_set_str);src/trace.c +1
-1@@ -165,13 +165,13 @@ const void *nftnl_trace_get_data(const struct nftnl_trace *trace, *data_len =sizeof (uint32_t );return &trace->type;case NFTNL_TRACE_CHAIN : - *data_len =strlen (trace->chain); + *data_len =strlen (trace->chain) +1 ;return trace->chain;
src/trace.c const void *nftnl_trace_get_data(const struct nftnl_trace *trace, · line 177
Quoted 10 lines
src/trace.c +2
-2case NFTNL_TRACE_TABLE : - *data_len =strlen (trace->table); + *data_len =strlen (trace->table) +1 ;return trace->table;case NFTNL_TRACE_JUMP_TARGET : - *data_len =strlen (trace->jump_target); + *data_len =strlen (trace->jump_target) +1 ;return trace->jump_target;case NFTNL_TRACE_TRANSPORT_HEADER : *data_len = trace->th.len;
Are you really sure we need this chunk too?
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH libnftnl] Fix string length calculations
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Carlos Falgueras García
These lengths must be one character longer to take account the null character
Please, place the change for
src/set.cin this patch so I only need to apply one patch.
I will send it now.
Quoted 77 lines
Another comment below.
Quoted 75 lines
Signed-off-by Carlos Falgueras García <[email protected]>--- src/chain.c | 2 +- src/rule.c | 2 +- src/set_elem.c | 2 +- src/table.c | 2 +- src/trace.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-)src/chain.c +1
-1@@ -260,7 +260,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_chain_set_u8, nft_chain_attr_set_u8);int nftnl_chain_set_str (struct nftnl_chain *c,uint16_t attr,const char *str) { -return nftnl_chain_set_data (c, attr, str,strlen (str)); +return nftnl_chain_set_data (c, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_chain_set_str, nft_chain_attr_set_str);src/rule.c +1
-1@@ -198,7 +198,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_rule_set_u64, nft_rule_attr_set_u64);int nftnl_rule_set_str (struct nftnl_rule *r,uint16_t attr,const char *str) { -return nftnl_rule_set_data (r, attr, str,strlen (str)); +return nftnl_rule_set_data (r, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_rule_set_str, nft_rule_attr_set_str);src/set_elem.c +1
-1@@ -149,7 +149,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_elem_set_u64, nft_set_elem_attr_set_u64);int nftnl_set_elem_set_str (struct nftnl_set_elem *s,uint16_t attr,const char *str) { -return nftnl_set_elem_set (s, attr, str,strlen (str)); +return nftnl_set_elem_set (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_elem_set_str, nft_set_elem_attr_set_str);src/table.c +1
-1@@ -131,7 +131,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_table_set_u8, nft_table_attr_set_u8);int nftnl_table_set_str (struct nftnl_table *t,uint16_t attr,const char *str) { -return nftnl_table_set_data (t, attr, str,0 ); +return nftnl_table_set_data (t, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_table_set_str, nft_table_attr_set_str);src/trace.c +2
-2@@ -165,13 +165,13 @@ const void *nftnl_trace_get_data(const struct nftnl_trace *trace, *data_len =sizeof (uint32_t );return &trace->type;case NFTNL_TRACE_CHAIN : - *data_len =strlen (trace->chain); + *data_len =strlen (trace->chain) +1 ;return trace->chain;case NFTNL_TRACE_TABLE : - *data_len =strlen (trace->table); + *data_len =strlen (trace->table) +1 ;
Quoted 8 lines
src/trace.c const void *nftnl_trace_get_data(const struct nftnl_trace *trace, · line 177
Quoted 7 lines
src/trace.c +1
-1return trace->table;case NFTNL_TRACE_JUMP_TARGET : - *data_len =strlen (trace->jump_target); + *data_len =strlen (trace->jump_target) +1 ;return trace->jump_target;case NFTNL_TRACE_TRANSPORT_HEADER : *data_len = trace->th.len;Are you really sure we need this chunk too?
Yes, I think the user would expect that 'data_len' means data length instead of data length minus one.
When checking other getters I realized that in most cases we keep the parameter 'data_len' unset when the user ask for a string. Maybe we can fix these behavior, I think it make more sense if our getters always return the data length instead of keep an inconstant behavior.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH libnftnl] Fix string length calculations
Quoted 22 lines · Carlos Falgueras García
Quoted 14 lines
Quoted 14 lines
src/trace.c +2
-2@@ -165,13 +165,13 @@ const void *nftnl_trace_get_data(const struct nftnl_trace *trace, *data_len =sizeof (uint32_t );return &trace->type;case NFTNL_TRACE_CHAIN : - *data_len =strlen (trace->chain); + *data_len =strlen (trace->chain) +1 ;return trace->chain;case NFTNL_TRACE_TABLE : - *data_len =strlen (trace->table); + *data_len =strlen (trace->table) +1 ;Quoted 8 lines
src/trace.c const void *nftnl_trace_get_data(const struct nftnl_trace *trace, · line 177
Quoted 7 lines
src/trace.c +1
-1return trace->table;case NFTNL_TRACE_JUMP_TARGET : - *data_len =strlen (trace->jump_target); + *data_len =strlen (trace->jump_target) +1 ;return trace->jump_target;case NFTNL_TRACE_TRANSPORT_HEADER : *data_len = trace->th.len;Are you really sure we need this chunk too?
Quoted 7 lines
Yes, I think the user would expect that '
data_len' means data length instead of data length minus one.When checking other getters I realized that in most cases we keep the parameter '
data_len' unset when the user ask for a string. Maybe we can fix these behavior, I think it make more sense if our getters always return the data length instead of keep an inconstant behavior.
_get() for strings functions should retain the strlen() semantics.
So I'd suggest you just fix the string setters.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 Fix nftnl_*_set_str
These lengths must be one character longer to take account the null character
--- src/chain.c | 2 +- src/rule.c | 2 +- src/set.c | 2 +- src/set_elem.c | 2 +- src/table.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
src/chain.c +1 -1
@@ -260,7 +260,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_chain_set_u8, nft_chain_attr_set_u8);int nftnl_chain_set_str (struct nftnl_chain *c,uint16_t attr,const char *str) { -return nftnl_chain_set_data (c, attr, str,strlen (str)); +return nftnl_chain_set_data (c, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_chain_set_str, nft_chain_attr_set_str);
src/rule.c +1 -1
@@ -198,7 +198,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_rule_set_u64, nft_rule_attr_set_u64);int nftnl_rule_set_str (struct nftnl_rule *r,uint16_t attr,const char *str) { -return nftnl_rule_set_data (r, attr, str,strlen (str)); +return nftnl_rule_set_data (r, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_rule_set_str, nft_rule_attr_set_str);
src/set.c +1 -1
@@ -203,7 +203,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_set_str, nft_set_attr_set_str);
src/set_elem.c +1 -1
@@ -149,7 +149,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_elem_set_u64, nft_set_elem_attr_set_u64);int nftnl_set_elem_set_str (struct nftnl_set_elem *s,uint16_t attr,const char *str) { -return nftnl_set_elem_set (s, attr, str,strlen (str)); +return nftnl_set_elem_set (s, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_set_elem_set_str, nft_set_elem_attr_set_str);
src/table.c +1 -1
@@ -131,7 +131,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_table_set_u8, nft_table_attr_set_u8);int nftnl_table_set_str (struct nftnl_table *t,uint16_t attr,const char *str) { -return nftnl_table_set_data (t, attr, str,0 ); +return nftnl_table_set_data (t, attr, str,strlen (str) +1 ); }EXPORT_SYMBOL_ALIAS (nftnl_table_set_str, nft_table_attr_set_str);
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 Fix nftnl_*_get to set data_len
All getters must set the output parameter 'data_len'
--- 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(+)
src/chain.c +3 -0
@@ -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 ;
src/expr.c +1 -0
@@ -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 :
src/expr/dynset.c +3 -0
@@ -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 ;
src/expr/lookup.c +3 -0
@@ -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 ;
src/gen.c +1 -0
@@ -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 ;
src/rule.c +2 -0
@@ -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 );
src/set.c +2 -0
@@ -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 );
src/set_elem.c +6 -0
@@ -160,25 +160,31 @@ const void *nftnl_set_elem_get(struct nftnl_set_elem *s, uint16_t attr, uint32_tswitch (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 ;
src/table.c +1 -0
@@ -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 );
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH 2/2 libnfntl] Fix nftnl_*_get to set data_len
Quoted 1 line · Carlos Falgueras García
All getters must set the output parameter '
data_len'
Then, send me a v2 that also replaces strlen(x) + 1 to strlen(x) from getters.
I can see several spots in src/expr/ that return strlen(x) + 1. So we leave this in consistent state in one go.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 Fix nftnl_*_get to set data_len
All getters must set the output parameter 'data_len'
--- 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(+)
src/chain.c +3 -0
@@ -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) +1 ;return c->name;case NFTNL_CHAIN_TABLE : + *data_len =strlen (c->table) +1 ;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) +1 ;return c->dev; }return NULL ;
src/expr.c +1 -0
@@ -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) +1 ; ret = expr->ops->name;break ;default :
src/expr/dynset.c +3 -0
@@ -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) +1 ;return dynset->set_name;case NFTNL_EXPR_DYNSET_SET_ID : + *data_len =sizeof (dynset->set_id) +1 ;return &dynset->set_id;case NFTNL_EXPR_DYNSET_EXPR : + *data_len =0 ;return dynset->expr; }return NULL ;
src/expr/lookup.c +3 -0
@@ -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) +1 ;return lookup->set_name;case NFTNL_EXPR_LOOKUP_SET_ID : + *data_len =sizeof (lookup->set_id) +1 ;return &lookup->set_id;case NFTNL_EXPR_LOOKUP_FLAGS : + *data_len =sizeof (lookup->flags) +1 ;return &lookup->flags; }return NULL ;
src/gen.c +1 -0
@@ -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) +1 ;return &gen->id; }return NULL ;
src/rule.c +2 -0
@@ -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) +1 ;return r->table;case NFTNL_RULE_CHAIN : + *data_len =strlen (r->chain) +1 ;return r->chain;case NFTNL_RULE_HANDLE : *data_len =sizeof (uint64_t );
src/set.c +2 -0
@@ -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) +1 ;return s->table;case NFTNL_SET_NAME : + *data_len =strlen (s->name) +1 ;return s->name;case NFTNL_SET_FLAGS : *data_len =sizeof (uint32_t );
src/set_elem.c +6 -0
@@ -160,25 +160,31 @@ const void *nftnl_set_elem_get(struct nftnl_set_elem *s, uint16_t attr, uint32_tswitch (attr) {case NFTNL_SET_ELEM_FLAGS : + *data_len =sizeof (s->set_elem_flags) +1 ;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) +1 ;return &s->data.verdict;case NFTNL_SET_ELEM_CHAIN :/* NFTA_SET_ELEM_DATA */ + *data_len =strlen (s->data.chain) +1 ;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) +1 ;return &s->timeout;case NFTNL_SET_ELEM_EXPIRATION :/* NFTA_SET_ELEM_EXPIRATION */ + *data_len =sizeof (s->expiration) +1 ;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 ;
src/table.c +1 -0
@@ -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) +1 ;return t->name;case NFTNL_TABLE_FLAGS : *data_len =sizeof (uint32_t );
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH v2, libnftnl] Fix nftnl_*_get to set data_len
Quoted 5 lines · Carlos Falgueras García
src/expr/lookup.c +0
-0
src/expr/lookup.c nftnl_expr_lookup_get(const struct nftnl_expr *e, uint16_t type, · line 82
Quoted 10 lines
src/expr/lookup.c +3
-0@@ -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) +1 ;return lookup->set_name;case NFTNL_EXPR_LOOKUP_SET_ID : + *data_len =sizeof (lookup->set_id) +1 ;return &lookup->set_id;case NFTNL_EXPR_LOOKUP_FLAGS : + *data_len =sizeof (lookup->flags) +1 ;
This + 1 here doesn't make any sense.
Please, send v3 without all these + 1.
And as I said in the previous version, you have to return strlen() as is. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/1 Fix nftnl_*_get to set data_len
All getters must set the output parameter 'data_len'
--- 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 + src/trace.c | 6 +++--- 10 files changed, 25 insertions(+), 3 deletions(-)
src/chain.c +3 -0
@@ -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) +1 ;return c->name;case NFTNL_CHAIN_TABLE : + *data_len =strlen (c->table) +1 ;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) +1 ;return c->dev; }return NULL ;
src/expr.c +1 -0
@@ -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) +1 ; ret = expr->ops->name;break ;default :
src/expr/dynset.c +3 -0
@@ -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) +1 ;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 ;
src/expr/lookup.c +3 -0
@@ -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) +1 ;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 ;
src/gen.c +1 -0
@@ -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 ;
src/rule.c +2 -0
@@ -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) +1 ;return r->table;case NFTNL_RULE_CHAIN : + *data_len =strlen (r->chain) +1 ;return r->chain;case NFTNL_RULE_HANDLE : *data_len =sizeof (uint64_t );
src/set.c +2 -0
@@ -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) +1 ;return s->table;case NFTNL_SET_NAME : + *data_len =strlen (s->name) +1 ;return s->name;case NFTNL_SET_FLAGS : *data_len =sizeof (uint32_t );
src/set_elem.c +6 -0
@@ -160,25 +160,31 @@ const void *nftnl_set_elem_get(struct nftnl_set_elem *s, uint16_t attr, uint32_tswitch (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) +1 ;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 ;
src/table.c +1 -0
@@ -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) +1 ;return t->name;case NFTNL_TABLE_FLAGS : *data_len =sizeof (uint32_t );
src/trace.c +3 -3
@@ -165,13 +165,13 @@ const void *nftnl_trace_get_data(const struct nftnl_trace *trace, *data_len =sizeof (uint32_t );return &trace->type;case NFTNL_TRACE_CHAIN : - *data_len =strlen (trace->chain); + *data_len =strlen (trace->chain) +1 ;return trace->chain;case NFTNL_TRACE_TABLE : - *data_len =strlen (trace->table); + *data_len =strlen (trace->table) +1 ;return trace->table;case NFTNL_TRACE_JUMP_TARGET : - *data_len =strlen (trace->jump_target); + *data_len =strlen (trace->jump_target) +1 ;return trace->jump_target;case NFTNL_TRACE_TRANSPORT_HEADER : *data_len = trace->th.len;
Signature · 6 lines
2.5.1 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3, libnftnl] Fix nftnl_*_get to set data_len
Quoted 1 line · Carlos Falgueras García
All getters must set the output parameter '
data_len'
Applied.
Carlos, I have enhanced this description. Please, include more detailed justifications on your follow up patches. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH 2/2 libnfntl] Fix nftnl_*_get to set data_len
In reply to Carlos Falgueras GarcíaCarlos,
Habla con Laura para ver cómo lleva este cambio en la reunión:
http://patchwork.ozlabs.org/patch/639253/
Si ella no anda con tiempo, creo que tú tienes los conocimientos para hacer este cambio que describo ahí.
No lo olvides. Gracias.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH 2/2 libnfntl] Fix nftnl_*_get to set data_len
Quoted 10 lines · Pablo Neira Ayuso
Carlos,
Habla con Laura para ver cómo lleva este cambio en la reunión:
http://patchwork.ozlabs.org/patch/639253/
Si ella no anda con tiempo, creo que tú tienes los conocimientos para hacer este cambio que describo ahí.
No lo olvides. Gracias.
Sorry, I accidentally sent this email to the mailing list in Spanish. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [PATCH 1/2 libnfntl] Fix nftnl_*_set_str
In reply to Carlos Falgueras GarcíaQuoted 2 lines · Carlos Falgueras García
These lengths must be one character longer to take account the null character
Applied, thanks Carlos.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 14 lines · Pablo Neira Ayuso
Quoted 13 lines · Carlos Falgueras García
We need the string length
Signed-off-by Carlos Falgueras García <[email protected]>--- src/set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)src/set.c +0
-0@@ -203,7 +203,7 @@ EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64);
Quoted 6 lines
src/set.c EXPORT_SYMBOL_ALIAS(nftnl_set_set_u64, nft_set_attr_set_u64); · line 206
Quoted 4 lines
src/set.c +1
-1int nftnl_set_set_str (struct nftnl_set *s,uint16_t attr,const char *str) { -return nftnl_set_set (s, attr, str); +return nftnl_set_set_data (s, attr, str,strlen (str));I think this should be strlen(str) + 1 so we make sure the string is nul-terminated.
Thanks Pablo. I have sent a v2 and another patch to fix this error in other code parts. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html