]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
obj/ct_timeout: Fix snprintf buffer length updates
authorPhil Sutter <phil@nwl.cc>
Tue, 9 Mar 2021 11:16:12 +0000 (12:16 +0100)
committerPhil Sutter <phil@nwl.cc>
Mon, 15 Mar 2021 11:23:04 +0000 (12:23 +0100)
Have to pass shrinking 'remain' variable to consecutive snprintf calls
instead of the unchanged 'len' parameter.

Fixes: 0adceeab1597a ("src: add ct timeout support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/obj/ct_timeout.c

index 2662cac69438d375df05ea6487595f30ca983f55..c3f577bdecd904f390fd02ae03843f566b340621 100644 (file)
@@ -266,12 +266,12 @@ static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len,
        struct nftnl_obj_ct_timeout *timeout = nftnl_obj_data(e);
 
        if (e->flags & (1 << NFTNL_OBJ_CT_TIMEOUT_L3PROTO)) {
-               ret = snprintf(buf + offset, len, "family %d ",
+               ret = snprintf(buf + offset, remain, "family %d ",
                               timeout->l3proto);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
        if (e->flags & (1 << NFTNL_OBJ_CT_TIMEOUT_L4PROTO)) {
-               ret = snprintf(buf + offset, len, "protocol %d ",
+               ret = snprintf(buf + offset, remain, "protocol %d ",
                                timeout->l4proto);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
@@ -283,7 +283,7 @@ static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len,
                if (timeout_protocol[timeout->l4proto].attr_max == 0)
                        l4num = IPPROTO_RAW;
 
-               ret = snprintf(buf + offset, len, "policy = {");
+               ret = snprintf(buf + offset, remain, "policy = {");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
                for (i = 0; i < timeout_protocol[l4num].attr_max; i++) {
@@ -293,13 +293,13 @@ static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len,
                                "UNKNOWN";
 
                        if (timeout->timeout[i] != timeout_protocol[l4num].dflt_timeout[i]) {
-                               ret = snprintf(buf + offset, len,
+                               ret = snprintf(buf + offset, remain,
                                        "%s = %u,", state_name, timeout->timeout[i]);
                                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                        }
                }
 
-               ret = snprintf(buf + offset, len, "}");
+               ret = snprintf(buf + offset, remain, "}");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
        buf[offset] = '\0';