summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-03-28 13:46:10 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2023-11-02 11:56:19 +0100
commitdc2d2cde6837f59871785e75ff2c46a865860f36 (patch)
treee0b7089961fc547beecfdfc23f3969b1f29f2728 /src
parent694d16b886db89125549f6f029c914b62b3f4c5b (diff)
xt: Fix translation error path
commit ce3d71348ee77d2d7ffa6a825afbc7471e92bc89 upstream. If xtables support was compiled in but the required libxtables DSO is not found, nft prints an error message and leaks memory: | counter packets 0 bytes 0 XT target MASQUERADE not found This is not as bad as it seems, the output combines stdout and stderr. Dropping stderr produces an incomplete ruleset listing, though. While this seemingly inline output can't easily be avoided, fix a few things: * Respect octx->error_fp, libnftables might have been configured to redirect stderr somewhere else. * Align error message formatting with others. * Don't return immediately, but free allocated memory and fall back to printing the expression in "untranslated" form. Fixes: 5c30feeee5cfe ("xt: Delay libxtables access until translation") Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src')
-rw-r--r--src/xt.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/xt.c b/src/xt.c
index 31cf40e0..6d5866d4 100644
--- a/src/xt.c
+++ b/src/xt.c
@@ -56,9 +56,10 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
case NFT_XT_MATCH:
mt = xtables_find_match(stmt->xt.name, XTF_TRY_LOAD, NULL);
if (!mt) {
- fprintf(stderr, "XT match %s not found\n",
+ fprintf(octx->error_fp,
+ "# Warning: XT match %s not found\n",
stmt->xt.name);
- return;
+ break;
}
size = XT_ALIGN(sizeof(*m)) + stmt->xt.infolen;
@@ -83,9 +84,10 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
case NFT_XT_TARGET:
tg = xtables_find_target(stmt->xt.name, XTF_TRY_LOAD);
if (!tg) {
- fprintf(stderr, "XT target %s not found\n",
+ fprintf(octx->error_fp,
+ "# Warning: XT target %s not found\n",
stmt->xt.name);
- return;
+ break;
}
size = XT_ALIGN(sizeof(*t)) + stmt->xt.infolen;