From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH v2 4/4] evaluate: Avoid undefined behaviour in concat_subtype_id()
Date: Tue, 30 Aug 2016 19:39:52 +0200 [thread overview]
Message-ID: <1472578792-2991-5-git-send-email-phil@nwl.cc> (raw)
In-Reply-To: <1472578792-2991-1-git-send-email-phil@nwl.cc>
For the left side of a concat expression, dtype is NULL and therefore
off is 0. In that case the code expects to get a datatype of
TYPE_INVALID, but this is fragile as the output of concat_subtype_id()
is undefined for n > 32 / TYPE_BITS.
To fix this, call datatype_lookup() directly passing the expected
TYPE_INVALID as argument if off is 0.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Understood (and reproduced) when the situation causing the undefined
behaviour happens.
- Understood what the code is supposed to do in that situation.
- Based on the information at hand, implemented a solution which avoids
undefined behaviour.
---
src/evaluate.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 194a03495b5fd..c1ee6b1929551 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -962,7 +962,10 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
"expressions",
i->dtype->name);
- tmp = concat_subtype_lookup(type, --off);
+ if (dtype == NULL)
+ tmp = datatype_lookup(TYPE_INVALID);
+ else
+ tmp = concat_subtype_lookup(type, --off);
expr_set_context(&ctx->ectx, tmp, tmp->size);
if (list_member_evaluate(ctx, &i) < 0)
--
2.8.2
next prev parent reply other threads:[~2016-08-30 17:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-30 17:39 [nft PATCH v2 0/4] A round of covscan indicated fixes Phil Sutter
2016-08-30 17:39 ` [nft PATCH v2 1/4] evaluate: Fix datalen checks in expr_evaluate_string() Phil Sutter
2016-09-05 16:37 ` Pablo Neira Ayuso
2016-08-30 17:39 ` [nft PATCH v2 2/4] netlink_delinearize: Avoid potential null pointer deref Phil Sutter
2016-09-05 16:52 ` Pablo Neira Ayuso
2016-09-06 14:17 ` Phil Sutter
2016-08-30 17:39 ` [nft PATCH v2 3/4] stmt_evaluate_reset: Have a generic fix for missing network context Phil Sutter
2016-09-05 16:53 ` Pablo Neira Ayuso
2016-08-30 17:39 ` Phil Sutter [this message]
2016-09-05 17:09 ` [nft PATCH v2 4/4] evaluate: Avoid undefined behaviour in concat_subtype_id() Pablo Neira Ayuso
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=1472578792-2991-5-git-send-email-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).