]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: remove NFT_NLATTR_LOC_MAX limit for netlink location error reporting
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 27 Jun 2022 08:16:48 +0000 (10:16 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 27 Jun 2022 09:59:51 +0000 (11:59 +0200)
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
src/cmd.c
src/rule.c

index 908122559cdf754dcd9de42938abdfbe2c0053c2..ad9f9127372286a92e7bad55b2d15bf28dfd7b13 100644 (file)
@@ -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
  *
@@ -717,11 +722,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_array_len;
+       uint32_t                num_attrs;
        const void              *arg;
 };
 
index f6a8aa11476830c9467e961bc41495167a5560b8..63692422e7655add37f93bc721283d8b1f7d646e 100644 (file)
--- 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)
index 0526a1482438b45be606258cd2cf008cbcecc506..c71f022670ef51bbaed6c93a7f7daa7ba10f00f5 100644 (file)
@@ -1279,6 +1279,9 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
        cmd->handle   = *h;
        cmd->location = *loc;
        cmd->data     = data;
+       cmd->attr     = xzalloc_array(NFT_NLATTR_LOC_MAX,
+                                     sizeof(struct nlerr_loc));
+       cmd->attr_array_len = NFT_NLATTR_LOC_MAX;
        init_list_head(&cmd->collapse_list);
 
        return cmd;
@@ -1286,8 +1289,10 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
 
 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_array_len) {
+               cmd->attr_array_len *= 2;
+               cmd->attr = xrealloc(cmd->attr, sizeof(struct nlerr_loc) * cmd->attr_array_len);
+       }
 
        cmd->attr[cmd->num_attrs].offset = offset;
        cmd->attr[cmd->num_attrs].location = loc;
@@ -1537,6 +1542,7 @@ void cmd_free(struct cmd *cmd)
                        BUG("invalid command object type %u\n", cmd->obj);
                }
        }
+       xfree(cmd->attr);
        xfree(cmd->arg);
        xfree(cmd);
 }