[nft,2/3] src: evaluate: don't rely on global chain ctx for error reporting
diff mbox series

Message ID 20190721001406.23785-3-fw@strlen.de
State Superseded
Delegated to: Pablo Neira
Headers show
Series
  • fix crash bug during rule restore
Related show

Commit Message

Florian Westphal July 21, 2019, 12:14 a.m. UTC
table inet filter {
}
table inet filter {
      chain test {
        counter
    }
}

will now report:
crash:7:13-16: Error: No such file or directory
      chain test {
            ^^^^
... which is still bogus, but we won't fallback to the 'internal'
location anymore and at least somehwat hint that there is a problem
with 'test' chain.

The error occurs because we're looking up the chain in the first
'table inet filter' instance, not the second.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/evaluate.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Patch
diff mbox series

diff --git a/src/evaluate.c b/src/evaluate.c
index 69b853f58722..b56932ccabcc 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -182,17 +182,17 @@  static int table_not_found(struct eval_ctx *ctx)
 			 family2str(table->handle.family));
 }
 
-static int chain_not_found(struct eval_ctx *ctx)
+static int chain_not_found(struct eval_ctx *ctx, struct handle *h)
 {
 	const struct table *table;
 	struct chain *chain;
 
-	chain = chain_lookup_fuzzy(&ctx->cmd->handle, &ctx->nft->cache, &table);
+	chain = chain_lookup_fuzzy(h, &ctx->nft->cache, &table);
 	if (chain == NULL)
-		return cmd_error(ctx, &ctx->cmd->handle.chain.location,
+		return cmd_error(ctx, &h->chain.location,
 				 "%s", strerror(ENOENT));
 
-	return cmd_error(ctx, &ctx->cmd->handle.chain.location,
+	return cmd_error(ctx, &h->chain.location,
 			 "%s; did you mean chain ā€˜%sā€™ in table %s ā€˜%sā€™?",
 			 strerror(ENOENT), chain->handle.chain.name,
 			 family2str(chain->handle.family),
@@ -3264,7 +3264,7 @@  static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
 
 	chain = chain_lookup(table, &rule->handle);
 	if (!chain)
-		return chain_not_found(ctx);
+		return chain_not_found(ctx, &rule->handle);
 
 	if (rule->handle.index.id) {
 		ref = rule_lookup_by_index(chain, rule->handle.index.id);
@@ -3710,7 +3710,7 @@  static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
 			return table_not_found(ctx);
 
 		if (chain_lookup(table, &cmd->handle) == NULL)
-			return chain_not_found(ctx);
+			return chain_not_found(ctx, &cmd->handle);
 
 		return 0;
 	case CMD_OBJ_QUOTA:
@@ -3843,7 +3843,7 @@  static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
 			return table_not_found(ctx);
 
 		if (chain_lookup(table, &ctx->cmd->handle) == NULL)
-			return chain_not_found(ctx);
+			return chain_not_found(ctx, &ctx->cmd->handle);
 
 		break;
 	default: