From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 2/3] src: remove NFT_NLATTR_LOC_MAX limit for netlink location error reporting
Date: Wed, 18 May 2022 20:04:34 +0200 [thread overview]
Message-ID: <20220518180435.298462-2-pablo@netfilter.org> (raw)
In-Reply-To: <20220518180435.298462-1-pablo@netfilter.org>
Set might have more than 16 elements, use a runtime array to store
netlink error location.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/rule.h | 13 ++++++++-----
src/cmd.c | 2 +-
src/rule.c | 10 ++++++++--
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/include/rule.h b/include/rule.h
index e232b97afed7..44e51847b70a 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -681,6 +681,11 @@ void monitor_free(struct monitor *m);
#define NFT_NLATTR_LOC_MAX 32
+struct nlerr_loc {
+ uint16_t offset;
+ const struct location *location;
+};
+
/**
* struct cmd - command statement
*
@@ -716,11 +721,9 @@ struct cmd {
struct markup *markup;
struct obj *object;
};
- struct {
- uint16_t offset;
- const struct location *location;
- } attr[NFT_NLATTR_LOC_MAX];
- int num_attrs;
+ struct nlerr_loc *attr;
+ uint32_t attr_size;
+ uint32_t num_attrs;
const void *arg;
};
diff --git a/src/cmd.c b/src/cmd.c
index f6a8aa114768..63692422e765 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -237,7 +237,7 @@ void nft_cmd_error(struct netlink_ctx *ctx, struct cmd *cmd,
struct mnl_err *err)
{
const struct location *loc = NULL;
- int i;
+ uint32_t i;
for (i = 0; i < cmd->num_attrs; i++) {
if (!cmd->attr[i].offset)
diff --git a/src/rule.c b/src/rule.c
index 799092eb15c5..78f47300d0fc 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1279,13 +1279,18 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
cmd->handle = *h;
cmd->location = *loc;
cmd->data = data;
+ cmd->attr = calloc(NFT_NLATTR_LOC_MAX, sizeof(struct nlerr_loc));
+ cmd->attr_size = NFT_NLATTR_LOC_MAX;
+
return cmd;
}
void cmd_add_loc(struct cmd *cmd, uint16_t offset, const struct location *loc)
{
- if (cmd->num_attrs >= NFT_NLATTR_LOC_MAX)
- return;
+ if (cmd->num_attrs >= cmd->attr_size) {
+ cmd->attr_size *= 2;
+ cmd->attr = reallocarray(cmd->attr, sizeof(struct nlerr_loc), cmd->attr_size);
+ }
cmd->attr[cmd->num_attrs].offset = offset;
cmd->attr[cmd->num_attrs].location = loc;
@@ -1462,6 +1467,7 @@ void cmd_free(struct cmd *cmd)
BUG("invalid command object type %u\n", cmd->obj);
}
}
+ xfree(cmd->attr);
xfree(cmd->arg);
xfree(cmd);
}
--
2.30.2
next prev parent reply other threads:[~2022-05-18 18:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 18:04 [PATCH nft 1/3] parser_bison: fix error location for set elements Pablo Neira Ayuso
2022-05-18 18:04 ` Pablo Neira Ayuso [this message]
2022-05-18 18:04 ` [PATCH nft 3/3] mnl: store netlink " Pablo Neira Ayuso
2022-06-27 10:31 ` [PATCH nft 1/3] parser_bison: fix " Pablo Neira Ayuso
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=20220518180435.298462-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.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).