netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libnftnl 1/3] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr()
@ 2017-10-04 12:09 Pablo Neira Ayuso
  2017-10-04 12:09 ` [PATCH libnftnl 2/3] expr: no need to nul-terminate buffer from expression ->snprintf indirection Pablo Neira Ayuso
  2017-10-04 12:09 ` [PATCH libnftnl 3/3] src: no need to nul-terminate buffer for nftnl_fprintf() calls Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:09 UTC (permalink / raw)
  To: netfilter-devel

This helper function deals with no ->snprintf() indirection in
expression and safe buffer nul-termination, use it.

Fixes: 059b9bf6fb31 ("src: Use nftnl_buf to export XML/JSON rules")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/buffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index f9d5a838c4ab..9ec86af121c9 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <buffer.h>
 #include <libnftnl/common.h>
+#include <libnftnl/expr.h>
 #include "internal.h"
 
 int nftnl_buf_update(struct nftnl_buf *b, int ret)
@@ -206,8 +207,8 @@ int nftnl_buf_expr(struct nftnl_buf *b, int type, uint32_t flags,
 	case NFTNL_OUTPUT_JSON:
 		nftnl_buf_put(b, "{");
 		nftnl_buf_str(b, type, expr->ops->name, TYPE);
-		ret = expr->ops->snprintf(b->buf + b->off, b->len, type, flags,
-					  expr);
+		ret = nftnl_expr_snprintf(b->buf + b->off, b->len, expr, type,
+					  flags);
 		if (ret > 0)
 			nftnl_buf_update(b, ret);
 		else
-- 
2.1.4


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

* [PATCH libnftnl 2/3] expr: no need to nul-terminate buffer from expression ->snprintf indirection
  2017-10-04 12:09 [PATCH libnftnl 1/3] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr() Pablo Neira Ayuso
@ 2017-10-04 12:09 ` Pablo Neira Ayuso
  2017-10-04 12:09 ` [PATCH libnftnl 3/3] src: no need to nul-terminate buffer for nftnl_fprintf() calls Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:09 UTC (permalink / raw)
  To: netfilter-devel

->snprintf() is always called via nftnl_expr_snprintf() wrapper, which
is already dealing with this corner case for us.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/expr/bitwise.c   | 3 ---
 src/expr/byteorder.c | 3 ---
 src/expr/cmp.c       | 3 ---
 src/expr/counter.c   | 3 ---
 src/expr/ct.c        | 3 ---
 src/expr/dup.c       | 3 ---
 src/expr/dynset.c    | 3 ---
 src/expr/exthdr.c    | 3 ---
 src/expr/fib.c       | 3 ---
 src/expr/fwd.c       | 3 ---
 src/expr/hash.c      | 3 ---
 src/expr/immediate.c | 3 ---
 src/expr/limit.c     | 3 ---
 src/expr/log.c       | 3 ---
 src/expr/lookup.c    | 3 ---
 src/expr/masq.c      | 3 ---
 src/expr/match.c     | 3 ---
 src/expr/meta.c      | 3 ---
 src/expr/nat.c       | 3 ---
 src/expr/numgen.c    | 3 ---
 src/expr/objref.c    | 3 ---
 src/expr/payload.c   | 3 ---
 src/expr/queue.c     | 3 ---
 src/expr/quota.c     | 3 ---
 src/expr/range.c     | 3 ---
 src/expr/redir.c     | 3 ---
 src/expr/reject.c    | 3 ---
 src/expr/rt.c        | 3 ---
 src/expr/target.c    | 3 ---
 29 files changed, 87 deletions(-)

diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
index ff9ade4d86d0..a89734b5f2d4 100644
--- a/src/expr/bitwise.c
+++ b/src/expr/bitwise.c
@@ -257,9 +257,6 @@ static int
 nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
 			    uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_bitwise_snprintf_default(buf, size, e);
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index 4bb95b497701..47c04cfea69f 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -272,9 +272,6 @@ static int
 nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
 			      uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_byteorder_snprintf_default(buf, size, e);
diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index 7bafaec573e7..b26d0eb08bb2 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -246,9 +246,6 @@ static int
 nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
 			uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_cmp_snprintf_default(buf, size, e);
diff --git a/src/expr/counter.c b/src/expr/counter.c
index 5c196d451843..21901e892471 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.c
@@ -164,9 +164,6 @@ static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
 				       uint32_t flags,
 				       const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_counter_snprintf_default(buf, len, e);
diff --git a/src/expr/ct.c b/src/expr/ct.c
index 021a27795a69..6f87a72487ae 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -317,9 +317,6 @@ static int
 nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
 		       uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_ct_snprintf_default(buf, len, e);
diff --git a/src/expr/dup.c b/src/expr/dup.c
index e2171f4ef1fb..ed8e6208cfab 100644
--- a/src/expr/dup.c
+++ b/src/expr/dup.c
@@ -170,9 +170,6 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
 				   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/dynset.c b/src/expr/dynset.c
index 2755d492e085..160d0e15c151 100644
--- a/src/expr/dynset.c
+++ b/src/expr/dynset.c
@@ -314,9 +314,6 @@ static int
 nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
 			   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_dynset_snprintf_default(buf, size, e);
diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index 11766fafc027..75cafbc113f7 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -339,9 +339,6 @@ static int
 nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
 			   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_exthdr_snprintf_default(buf, len, e);
diff --git a/src/expr/fib.c b/src/expr/fib.c
index cbadeef7ce49..b922b26681e7 100644
--- a/src/expr/fib.c
+++ b/src/expr/fib.c
@@ -236,9 +236,6 @@ static int
 nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
 			 uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_fib_snprintf_default(buf, len, e);
diff --git a/src/expr/fwd.c b/src/expr/fwd.c
index 38923df64760..1312ea10b07c 100644
--- a/src/expr/fwd.c
+++ b/src/expr/fwd.c
@@ -147,9 +147,6 @@ static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
 				   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/hash.c b/src/expr/hash.c
index 066c790d5b50..fcc4fa5c0516 100644
--- a/src/expr/hash.c
+++ b/src/expr/hash.c
@@ -288,9 +288,6 @@ static int
 nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
 			 uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_hash_snprintf_default(buf, len, e);
diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index aba84ea0823e..b0570bd539a4 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -262,9 +262,6 @@ static int
 nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
 			      uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch(type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/limit.c b/src/expr/limit.c
index 8e1f02abb617..856ab1839b0a 100644
--- a/src/expr/limit.c
+++ b/src/expr/limit.c
@@ -243,9 +243,6 @@ static int
 nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
 			  uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch(type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_limit_snprintf_default(buf, len, e);
diff --git a/src/expr/log.c b/src/expr/log.c
index 161327b4b5f2..86d965136cd4 100644
--- a/src/expr/log.c
+++ b/src/expr/log.c
@@ -301,9 +301,6 @@ static int
 nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
 			uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch(type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_log_snprintf_default(buf, len, e);
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 32220a30dbce..5fcb81f3a7a2 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -242,9 +242,6 @@ static int
 nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
 			   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch(type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_lookup_snprintf_default(buf, size, e);
diff --git a/src/expr/masq.c b/src/expr/masq.c
index 1c75ee9cdd53..7c235d3b0bdc 100644
--- a/src/expr/masq.c
+++ b/src/expr/masq.c
@@ -190,9 +190,6 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
 				    uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_masq_snprintf_default(buf, len, e);
diff --git a/src/expr/match.c b/src/expr/match.c
index af659b3821c8..dd09e1e85192 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -200,9 +200,6 @@ nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
 {
 	struct nftnl_expr_match *match = nftnl_expr_data(e);
 
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return snprintf(buf, len, "name %s rev %u ",
diff --git a/src/expr/meta.c b/src/expr/meta.c
index b5c27e66dc51..2c758412bf2e 100644
--- a/src/expr/meta.c
+++ b/src/expr/meta.c
@@ -252,9 +252,6 @@ static int
 nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
 			 uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_meta_snprintf_default(buf, len, e);
diff --git a/src/expr/nat.c b/src/expr/nat.c
index 350633fd5e0a..92713033a6e7 100644
--- a/src/expr/nat.c
+++ b/src/expr/nat.c
@@ -339,9 +339,6 @@ static int
 nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
 			uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_nat_snprintf_default(buf, size, e);
diff --git a/src/expr/numgen.c b/src/expr/numgen.c
index 9b5b1b789206..1369b01d9401 100644
--- a/src/expr/numgen.c
+++ b/src/expr/numgen.c
@@ -224,9 +224,6 @@ static int
 nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
 		       uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_ng_snprintf_default(buf, len, e);
diff --git a/src/expr/objref.c b/src/expr/objref.c
index b4b3383e8a7c..4cfa3cbfbd2b 100644
--- a/src/expr/objref.c
+++ b/src/expr/objref.c
@@ -236,9 +236,6 @@ static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
 				      uint32_t flags,
 				      const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_objref_snprintf_default(buf, len, e);
diff --git a/src/expr/payload.c b/src/expr/payload.c
index 897fc7746166..91e1587ff239 100644
--- a/src/expr/payload.c
+++ b/src/expr/payload.c
@@ -290,9 +290,6 @@ nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
 {
 	struct nftnl_expr_payload *payload = nftnl_expr_data(e);
 
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		if (payload->sreg)
diff --git a/src/expr/queue.c b/src/expr/queue.c
index e0fb785a490b..a392a271a6fb 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -235,9 +235,6 @@ static int
 nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
 			  uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_queue_snprintf_default(buf, len, e);
diff --git a/src/expr/quota.c b/src/expr/quota.c
index c247b0a03341..667e6e17c28c 100644
--- a/src/expr/quota.c
+++ b/src/expr/quota.c
@@ -183,9 +183,6 @@ static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
 				       uint32_t flags,
 				       const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_quota_snprintf_default(buf, len, e);
diff --git a/src/expr/range.c b/src/expr/range.c
index c7bb7c7f3d7a..b2789ffaada3 100644
--- a/src/expr/range.c
+++ b/src/expr/range.c
@@ -263,9 +263,6 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
 static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
 				     uint32_t flags, const struct nftnl_expr *e)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_range_snprintf_default(buf, size, e);
diff --git a/src/expr/redir.c b/src/expr/redir.c
index 9fb634afaa19..b2aa3453870a 100644
--- a/src/expr/redir.c
+++ b/src/expr/redir.c
@@ -204,9 +204,6 @@ static int
 nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
 			  uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_redir_snprintf_default(buf, len, e);
diff --git a/src/expr/reject.c b/src/expr/reject.c
index 1e6fdf5c5ba0..11d8b20096ae 100644
--- a/src/expr/reject.c
+++ b/src/expr/reject.c
@@ -164,9 +164,6 @@ static int
 nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
 			   uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_reject_snprintf_default(buf, len, e);
diff --git a/src/expr/rt.c b/src/expr/rt.c
index 10cb1e27ce68..62c01a0be0f5 100644
--- a/src/expr/rt.c
+++ b/src/expr/rt.c
@@ -203,9 +203,6 @@ static int
 nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
 		       uint32_t flags, const struct nftnl_expr *e)
 {
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return nftnl_expr_rt_snprintf_default(buf, len, e);
diff --git a/src/expr/target.c b/src/expr/target.c
index 3c58b03d20dd..ed4bf7df6328 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -200,9 +200,6 @@ nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
 {
 	struct nftnl_expr_target *target = nftnl_expr_data(e);
 
-	if (len)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 		return snprintf(buf, len, "name %s rev %u ",
-- 
2.1.4


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

* [PATCH libnftnl 3/3] src: no need to nul-terminate buffer for nftnl_fprintf() calls
  2017-10-04 12:09 [PATCH libnftnl 1/3] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr() Pablo Neira Ayuso
  2017-10-04 12:09 ` [PATCH libnftnl 2/3] expr: no need to nul-terminate buffer from expression ->snprintf indirection Pablo Neira Ayuso
@ 2017-10-04 12:09 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:09 UTC (permalink / raw)
  To: netfilter-devel

This function bails out with -1 if we cannot print, and this buffer is
internally allocated. No need for this overly deffensive initialization.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/chain.c    | 3 ---
 src/gen.c      | 3 ---
 src/object.c   | 3 ---
 src/rule.c     | 3 ---
 src/set.c      | 3 ---
 src/set_elem.c | 3 ---
 src/table.c    | 3 ---
 7 files changed, 21 deletions(-)

diff --git a/src/chain.c b/src/chain.c
index 6df871df4131..5e30a8016cac 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -867,9 +867,6 @@ EXPORT_SYMBOL(nftnl_chain_snprintf);
 static int nftnl_chain_do_snprintf(char *buf, size_t size, const void *c,
 				   uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_chain_snprintf(buf, size, c, type, flags);
 }
 
diff --git a/src/gen.c b/src/gen.c
index a03648bba1c2..e42dd4055cb4 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -203,9 +203,6 @@ EXPORT_SYMBOL(nftnl_gen_snprintf);
 static int nftnl_gen_do_snprintf(char *buf, size_t size, const void *gen,
 				 uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf = '\0';
-
 	return nftnl_gen_snprintf(buf, size, gen, type, flags);
 }
 
diff --git a/src/object.c b/src/object.c
index 8dc83b36c32e..f907dd22d13a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -488,9 +488,6 @@ EXPORT_SYMBOL(nftnl_obj_snprintf);
 static int nftnl_obj_do_snprintf(char *buf, size_t size, const void *obj,
 				 uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_obj_snprintf(buf, size, obj, type, flags);
 }
 
diff --git a/src/rule.c b/src/rule.c
index f37806c0e07b..7cbd15bbd93c 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -836,9 +836,6 @@ EXPORT_SYMBOL(nftnl_rule_snprintf);
 static int nftnl_rule_do_snprintf(char *buf, size_t size, const void *r,
 				  uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_rule_snprintf(buf, size, r, type, flags);
 }
 
diff --git a/src/set.c b/src/set.c
index a4e41d2a3547..36e59c38536c 100644
--- a/src/set.c
+++ b/src/set.c
@@ -939,9 +939,6 @@ EXPORT_SYMBOL(nftnl_set_snprintf);
 static int nftnl_set_do_snprintf(char *buf, size_t size, const void *s,
 				 uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_set_snprintf(buf, size, s, type, flags);
 }
 
diff --git a/src/set_elem.c b/src/set_elem.c
index a8f88a4f1813..a99876a90cac 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -738,9 +738,6 @@ static int nftnl_set_elem_do_snprintf(char *buf, size_t size, const void *e,
 				      uint32_t cmd, uint32_t type,
 				      uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_set_elem_snprintf(buf, size, e, type, flags);
 }
 
diff --git a/src/table.c b/src/table.c
index 4d8176c9be78..db870cd98437 100644
--- a/src/table.c
+++ b/src/table.c
@@ -417,9 +417,6 @@ EXPORT_SYMBOL(nftnl_table_snprintf);
 static int nftnl_table_do_snprintf(char *buf, size_t size, const void *t,
 				   uint32_t cmd, uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	return nftnl_table_snprintf(buf, size, t, type, flags);
 }
 
-- 
2.1.4


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

end of thread, other threads:[~2017-10-04 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-04 12:09 [PATCH libnftnl 1/3] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr() Pablo Neira Ayuso
2017-10-04 12:09 ` [PATCH libnftnl 2/3] expr: no need to nul-terminate buffer from expression ->snprintf indirection Pablo Neira Ayuso
2017-10-04 12:09 ` [PATCH libnftnl 3/3] src: no need to nul-terminate buffer for nftnl_fprintf() calls 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).