From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft] expression: don't try to import empty string
Date: Mon, 31 Mar 2025 18:10:07 +0200 [thread overview]
Message-ID: <Z-q-X4Yhkn3vXD3p@calendula> (raw)
In-Reply-To: <20250331123715.GA12883@breakpoint.cc>
On Mon, Mar 31, 2025 at 02:37:15PM +0200, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > Hi Florian,
> >
> > On Thu, Mar 27, 2025 at 04:17:11PM +0100, Florian Westphal wrote:
> > > The bogon will trigger the assertion in mpz_import_data:
> > > src/expression.c:418: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
> >
> > I took a quick look searching for {s:s} in src/parser_json.c
> >
> > The common idiom is json_parse_err() then a helper parser function to
> > validate the string.
> >
> > It seems it is missing in this case. Maybe tigthen json parser instead?
> >
> > Caller invoking constant_expr_alloc() with data != NULL but no len
> > looks broken to me.
>
> return constant_expr_alloc(int_loc, &string_type, BYTEORDER_HOST_ENDIAN,
> strlen(chain) * BITS_PER_BYTE, chain);
>
> chain name is '""'.
>
> There are other spots where we possibly call into constant_expr_alloc()
> with a 0 argument.
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
> I think it would be a lot more work and bloat to add all the checks on
> the json side while its a one-liner in constant_expr_alloc().
I don't think this is needed, the idiom in src/parser_json.c is to:
1) fetch string
2) validate it
For example:
if (!json_unpack(root, "{s:s}", "ttl", &ttl)) {
if (!strcmp(ttl, "loose")) {
ttlval = 1;
} else if (!strcmp(ttl, "skip")) {
ttlval = 2;
} else {
json_error(ctx, "Invalid osf ttl option '%s'.", ttl);
return NULL;
}
}
> I could also add json_constant_expr_alloc() but it seems kinda silly to me.
I agree, I don't think json_constant_expr_alloc is needed.
prev parent reply other threads:[~2025-03-31 16:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 15:17 [PATCH nft] expression: don't try to import empty string Florian Westphal
2025-03-31 11:22 ` Pablo Neira Ayuso
2025-03-31 12:37 ` Florian Westphal
2025-03-31 16:10 ` Pablo Neira Ayuso [this message]
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=Z-q-X4Yhkn3vXD3p@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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.