netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftnl PATCH] utils: nft_fprintf: prevent an empty buffer from being printed
@ 2014-09-12 19:41 Arturo Borrero Gonzalez
  2014-09-16 17:30 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Arturo Borrero Gonzalez @ 2014-09-12 19:41 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

If the snprintf_cb() printed 0 characters, no \0 exists in the buffer.
Also, in that case fprintf() is meant to print nothing, so we can just exit.

This patch addresses new cases of textual output by libnftnl with trash.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 src/utils.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/utils.c b/src/utils.c
index 96c8bf2..d70fbf1 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -190,7 +190,7 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
 	int ret;
 
 	ret = snprintf_cb(buf, bufsiz, obj, type, flags);
-	if (ret < 0)
+	if (ret <= 0)
 		goto out;
 
 	if (ret >= NFT_SNPRINTF_BUFSIZ) {
@@ -201,7 +201,7 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
 			return -1;
 
 		ret = snprintf_cb(buf, bufsiz, obj, type, flags);
-		if (ret < 0)
+		if (ret <= 0)
 			goto out;
 	}
 


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

* Re: [libnftnl PATCH] utils: nft_fprintf: prevent an empty buffer from being printed
  2014-09-12 19:41 [libnftnl PATCH] utils: nft_fprintf: prevent an empty buffer from being printed Arturo Borrero Gonzalez
@ 2014-09-16 17:30 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2014-09-16 17:30 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Fri, Sep 12, 2014 at 09:41:25PM +0200, Arturo Borrero Gonzalez wrote:
> If the snprintf_cb() printed 0 characters, no \0 exists in the buffer.
> Also, in that case fprintf() is meant to print nothing, so we can just exit.
> 
> This patch addresses new cases of textual output by libnftnl with trash.

Also applied, thanks.


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

end of thread, other threads:[~2014-09-16 17:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-12 19:41 [libnftnl PATCH] utils: nft_fprintf: prevent an empty buffer from being printed Arturo Borrero Gonzalez
2014-09-16 17:30 ` 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).