]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: use existing table object from evaluation context
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 9 Sep 2015 23:30:06 +0000 (01:30 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 11 Sep 2015 12:32:04 +0000 (14:32 +0200)
Skip table object lookup if we are in the context of table declaration already,
ctx->table already points to the right table we have to use during the
evalution. Otherwise, a list corruption occurs when using the wrong table
object when it already exists in the kernel.

http://marc.info/?l=netfilter-devel&m=144179814209295&w=2

Reported-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Tested-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
src/evaluate.c

index 1405da83e0d83c9ae17992c180fd54cb96acac4d..22dd6d56399b5a40c4f5dec20c64e2c187b7414d 100644 (file)
@@ -1711,12 +1711,26 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
        }
 }
 
+static struct table *table_lookup_global(struct eval_ctx *ctx)
+{
+       struct table *table;
+
+       if (ctx->table != NULL)
+               return ctx->cmd->table;
+
+       table = table_lookup(&ctx->cmd->handle);
+       if (table == NULL)
+               return NULL;
+
+       return table;
+}
+
 static int setelem_evaluate(struct eval_ctx *ctx, struct expr **expr)
 {
        struct table *table;
        struct set *set;
 
-       table = table_lookup(&ctx->cmd->handle);
+       table = table_lookup_global(ctx);
        if (table == NULL)
                return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
                                 ctx->cmd->handle.table);
@@ -1739,7 +1753,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
        struct table *table;
        const char *type;
 
-       table = table_lookup(&ctx->cmd->handle);
+       table = table_lookup_global(ctx);
        if (table == NULL)
                return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
                                 ctx->cmd->handle.table);
@@ -1857,9 +1871,9 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
        struct table *table;
        struct rule *rule;
 
-       table = table_lookup(&ctx->cmd->handle);
+       table = table_lookup_global(ctx);
        if (table == NULL)
-               return cmd_error(ctx, "Table '%s' does not exist",
+               return cmd_error(ctx, "Could not process rule: Table '%s' does not exist",
                                 ctx->cmd->handle.table);
 
        if (chain == NULL) {