[libnftnl PATCH 1/2] utils: ensure \0 is in place in nft_fprintf()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We must make sure the buffer contains a \0 in the last position,
to avoid printing trash by the last fprintf() call.

This is needed because if the internal snprintf callback prints nothing,
no \0 exists in the buffer.

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

diff --git a/src/utils.c b/src/utils.c
index 96c8bf2..8a7c521 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -189,6 +189,8 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
 	size_t bufsiz = sizeof(_buf);
 	int ret;
 
+	buf[0] = '\0';
+
 	ret = snprintf_cb(buf, bufsiz, obj, type, flags);
 	if (ret < 0)
 		goto out;
@@ -200,6 +202,8 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
 		if (buf == NULL)
 			return -1;
 
+		buf[0] = '\0';
+
 		ret = snprintf_cb(buf, bufsiz, obj, type, flags);
 		if (ret < 0)
 			goto out;

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




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux