]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
expr: Fix snprintf buffer length updates
authorPhil Sutter <phil@nwl.cc>
Tue, 9 Mar 2021 10:14:29 +0000 (11:14 +0100)
committerPhil Sutter <phil@nwl.cc>
Mon, 15 Mar 2021 11:22:56 +0000 (12:22 +0100)
Subsequent calls to snprintf() sometimes reuse 'len' variable although
they should refer to the updated value in 'remain' instead.

Fixes: 676ea569bbe5a ("src: Change parameters of SNPRINTF_BUFFER_SIZE macro.")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/expr/ct.c
src/expr/dup.c
src/expr/queue.c
src/expr/redir.c

index 124de9dd2b33aee447bd9ba66a8ecac6dd9ff235..1a21c953c9be2b9757a2b98f4e41fb580d3160a5 100644 (file)
@@ -230,7 +230,7 @@ nftnl_expr_ct_snprintf_default(char *buf, size_t size,
        struct nftnl_expr_ct *ct = nftnl_expr_data(e);
 
        if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) {
-               ret = snprintf(buf, size, "set %s with reg %u ",
+               ret = snprintf(buf, remain, "set %s with reg %u ",
                                ctkey2str(ct->key), ct->sreg);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
index ac398394aed068ada104c23e0898b8823711c623..7a3ee96361644bd55172b909415e20d5be9c83be 100644 (file)
@@ -119,12 +119,12 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
        struct nftnl_expr_dup *dup = nftnl_expr_data(e);
 
        if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_ADDR)) {
-               ret = snprintf(buf + offset, len, "sreg_addr %u ", dup->sreg_addr);
+               ret = snprintf(buf + offset, remain, "sreg_addr %u ", dup->sreg_addr);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_DEV)) {
-               ret = snprintf(buf + offset, len, "sreg_dev %u ", dup->sreg_dev);
+               ret = snprintf(buf + offset, remain, "sreg_dev %u ", dup->sreg_dev);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
index 051ef71e72fdb873e48ebdea28ac277ffd0ade71..b892b57bc48974fd43796a8d54eb860dbcadbb16 100644 (file)
@@ -153,31 +153,31 @@ static int nftnl_expr_queue_snprintf_default(char *buf, size_t len,
        if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM)) {
                total_queues = queue->queuenum + queue->queues_total - 1;
 
-               ret = snprintf(buf + offset, len, "num %u", queue->queuenum);
+               ret = snprintf(buf + offset, remain, "num %u", queue->queuenum);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
                if (queue->queues_total && total_queues != queue->queuenum) {
-                       ret = snprintf(buf + offset, len, "-%u", total_queues);
+                       ret = snprintf(buf + offset, remain, "-%u", total_queues);
                        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                }
 
-               ret = snprintf(buf + offset, len, " ");
+               ret = snprintf(buf + offset, remain, " ");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (e->flags & (1 << NFTNL_EXPR_QUEUE_SREG_QNUM)) {
-               ret = snprintf(buf + offset, len, "sreg_qnum %u ",
+               ret = snprintf(buf + offset, remain, "sreg_qnum %u ",
                               queue->sreg_qnum);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS)) {
                if (queue->flags & (NFT_QUEUE_FLAG_BYPASS)) {
-                       ret = snprintf(buf + offset, len, "bypass ");
+                       ret = snprintf(buf + offset, remain, "bypass ");
                        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                }
                if (queue->flags & (NFT_QUEUE_FLAG_CPU_FANOUT)) {
-                       ret = snprintf(buf + offset, len, "fanout ");
+                       ret = snprintf(buf + offset, remain, "fanout ");
                        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                }
        }
index 477659a320db1950eafac9c5b85ed073d08fae50..c00c2a6ddf3cf545be91accb1984888269bbf443 100644 (file)
@@ -138,19 +138,19 @@ static int nftnl_expr_redir_snprintf_default(char *buf, size_t len,
        struct nftnl_expr_redir *redir = nftnl_expr_data(e);
 
        if (nftnl_expr_is_set(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN)) {
-               ret = snprintf(buf + offset, len, "proto_min reg %u ",
+               ret = snprintf(buf + offset, remain, "proto_min reg %u ",
                               redir->sreg_proto_min);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (nftnl_expr_is_set(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX)) {
-               ret = snprintf(buf + offset, len, "proto_max reg %u ",
+               ret = snprintf(buf + offset, remain, "proto_max reg %u ",
                               redir->sreg_proto_max);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (nftnl_expr_is_set(e, NFTNL_EXPR_REDIR_FLAGS)) {
-               ret = snprintf(buf + offset, len, "flags 0x%x ",
+               ret = snprintf(buf + offset, remain, "flags 0x%x ",
                               redir->flags);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }