From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH 01/10] expr: Fix snprintf buffer length updates
Date: Tue, 9 Mar 2021 16:45:07 +0100 [thread overview]
Message-ID: <20210309154516.4987-2-phil@nwl.cc> (raw)
In-Reply-To: <20210309154516.4987-1-phil@nwl.cc>
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 | 2 +-
src/expr/dup.c | 4 ++--
src/expr/queue.c | 12 ++++++------
src/expr/redir.c | 6 +++---
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/expr/ct.c b/src/expr/ct.c
index 124de9dd2b33a..1a21c953c9be2 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -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);
}
diff --git a/src/expr/dup.c b/src/expr/dup.c
index ac398394aed06..7a3ee96361644 100644
--- a/src/expr/dup.c
+++ b/src/expr/dup.c
@@ -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);
}
diff --git a/src/expr/queue.c b/src/expr/queue.c
index 051ef71e72fdb..b892b57bc4897 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -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);
}
}
diff --git a/src/expr/redir.c b/src/expr/redir.c
index 477659a320db1..c00c2a6ddf3cf 100644
--- a/src/expr/redir.c
+++ b/src/expr/redir.c
@@ -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);
}
--
2.30.1
next prev parent reply other threads:[~2021-03-09 15:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-09 15:45 [libnftnl PATCH 00/10] Kill non-default output leftovers Phil Sutter
2021-03-09 15:45 ` Phil Sutter [this message]
2021-03-09 15:45 ` [libnftnl PATCH 02/10] obj/ct_expect: Fix snprintf buffer length updates Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 03/10] obj/ct_timeout: " Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 04/10] object: Fix for wrong parameter passed to snprintf callback Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 05/10] expr: Check output type once and for all Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 06/10] expr/data_reg: Drop output_format parameter Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 07/10] obj: Drop type parameter from snprintf callback Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 08/10] Drop pointless local variable in snprintf callbacks Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 09/10] Get rid of single option switch statements Phil Sutter
2021-03-09 15:45 ` [libnftnl PATCH 10/10] ruleset: Eliminate tag and separator helpers Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210309154516.4987-2-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).