diff mbox series

[libnftnl,02/10] obj/ct_expect: Fix snprintf buffer length updates

Message ID 20210309154516.4987-3-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series Kill non-default output leftovers | expand

Commit Message

Phil Sutter March 9, 2021, 3:45 p.m. UTC
Have to pass shrinking 'remain' variable to consecutive snprintf calls
instead of the unchanged 'len' parameter.

Fixes: c4b6aa09b85d2 ("src: add ct expectation support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/obj/ct_expect.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/obj/ct_expect.c b/src/obj/ct_expect.c
index c0bb5bad0246b..0b4eb8fe541d9 100644
--- a/src/obj/ct_expect.c
+++ b/src/obj/ct_expect.c
@@ -159,23 +159,27 @@  static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len,
 	struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e);
 
 	if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L3PROTO)) {
-		ret = snprintf(buf + offset, len, "family %d ", exp->l3proto);
+		ret = snprintf(buf + offset, remain,
+			       "family %d ", exp->l3proto);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
 	if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L4PROTO)) {
-		ret = snprintf(buf + offset, len, "protocol %d ", exp->l4proto);
+		ret = snprintf(buf + offset, remain,
+			       "protocol %d ", exp->l4proto);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
 	if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_DPORT)) {
-		ret = snprintf(buf + offset, len, "dport %d ", exp->dport);
+		ret = snprintf(buf + offset, remain,
+			       "dport %d ", exp->dport);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
 	if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_TIMEOUT)) {
-		ret = snprintf(buf + offset, len, "timeout %d ", exp->timeout);
+		ret = snprintf(buf + offset, remain,
+			       "timeout %d ", exp->timeout);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
 	if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_SIZE)) {
-		ret = snprintf(buf + offset, len, "size %d ", exp->size);
+		ret = snprintf(buf + offset, remain, "size %d ", exp->size);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}