diff mbox

[libnftnl] utils: nft_fprintf: prevent an empty buffer from being printed

Message ID 20140912194125.9222.51509.stgit@nfdev.cica.es
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Arturo Borrero Sept. 12, 2014, 7:41 p.m. UTC
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(-)


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

Comments

Pablo Neira Ayuso Sept. 16, 2014, 5:30 p.m. UTC | #1
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.

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

Patch

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;
 	}