Skip to contentSkip to conversation

utils: nft_fprintf: prevent an empty buffer from being printed

PATCH In review Arturo Borrero Gonzalez 2 participants 2 messages Sep 12, 2014 – Sep 16, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: nft_fprintf: prevent an empty buffer from being printed

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.

---
 src/utils.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/utils.c +2 -2
index 96c8bf2..d70fbf1 100644
@@ -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;
 	}
 
#1 lore raw
Quoted 4 lines · Arturo Borrero Gonzalez

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.