From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 1/3] parser_json: Avoid storage leak in json_parse_set_expr error path
Date: Wed, 11 Nov 2026 18:01:45 +0100 [thread overview]
Message-ID: <20261111170147.47501-2-phil@nwl.cc> (raw)
In-Reply-To: <20261111170147.47501-1-phil@nwl.cc>
If parsing jright fails, code frees 'expr' and 'set_expr' before
returning but 'elem' may have been allocated as well. To avoid extra
conditionals when freeing it, parse jright earlier so the code following
conditional 'elem' allocation becomes error-path-free.
Fixes: 144d97e151adb ("src: normalize set element with EXPR_MAPPING")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/parser_json.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/parser_json.c b/src/parser_json.c
index 14259ea39777b..224cbb79de1b8 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1493,13 +1493,6 @@ static struct expr *json_parse_set_expr(struct json_ctx *ctx,
return NULL;
}
- if (expr->etype != EXPR_SET_ELEM) {
- elem = set_elem_expr_alloc(int_loc, expr);
- } else {
- elem = expr;
- expr = expr->key;
- }
-
expr2 = json_parse_set_rhs_expr(ctx, jright);
if (!expr2) {
json_error(ctx, "Invalid set elem at index %zu.", index);
@@ -1507,6 +1500,14 @@ static struct expr *json_parse_set_expr(struct json_ctx *ctx,
expr_free(set_expr);
return NULL;
}
+
+ if (expr->etype != EXPR_SET_ELEM) {
+ elem = set_elem_expr_alloc(int_loc, expr);
+ } else {
+ elem = expr;
+ expr = expr->key;
+ }
+
expr2 = mapping_expr_alloc(int_loc, expr, expr2);
elem->key = expr2;
expr = elem;
--
2.54.0
next prev parent reply other threads:[~2026-11-11 17:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 17:01 [nft PATCH 0/3] Fix two leaks in error path, one extra Phil Sutter
2026-11-11 17:01 ` Phil Sutter [this message]
2026-11-11 17:01 ` [nft PATCH 2/3] netlink: Avoid storage leak in tunnel_parse_opt_cb error path Phil Sutter
2026-11-11 17:01 ` [nft PATCH 3/3] bison: Drop pointless NULL-check Phil Sutter
2026-11-11 20:04 ` [nft PATCH 0/3] Fix two leaks in error path, one extra Florian Westphal
2026-11-11 22:57 ` Phil Sutter
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=20261111170147.47501-2-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.