From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Harsha Sharma <harshasharmaiitr@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH] src: Add option '-D' to define variables from command-line
Date: Mon, 4 Dec 2017 12:06:35 +0100 [thread overview]
Message-ID: <20171204110635.GA19724@salvia> (raw)
In-Reply-To: <20171204105259.28070-1-harshasharmaiitr@gmail.com>
On Mon, Dec 04, 2017 at 04:22:59PM +0530, Harsha Sharma wrote:
> This patch adds option '-D' with optarg in form test="foo" to define
> variable to be referenced from input file.
>
> For eg.
> nft -D test="foo" -f /tmp/test1
Could you generalize this to take comma separated list of variables,
ie.
nft -D test="foo",test2="bar" -f /tmp/test1
> Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
> ---
> This patch passes identifier and its value as nft_ctx struct members
> and binds variable with symbol_bind and when symbol_lookup is called
> while parsing, then comparison returns true, but this patch causes
> segmentation fault.
Valgrind can help you know where the crash is going on.
# cat /tmp/x
add table x
add chain x y
add rule x y ip saddr $test
# valgrind nft -D test="1.1.1.1" -f /tmp/x
[...]
==23100== Invalid read of size 8
==23100== at 0x40E31A: expr_clone (expression.c:52)
==23100== by 0x439826: expr_evaluate_symbol (evaluate.c:191)
==23100== by 0x439826: expr_evaluate (evaluate.c:1790)
==23100== by 0x43855D: expr_evaluate_relational (evaluate.c:1569)
==23100== by 0x43855D: expr_evaluate (evaluate.c:1830)
==23100== by 0x436F93: stmt_evaluate_expr (evaluate.c:1843)
==23100== by 0x436F93: stmt_evaluate (evaluate.c:2780)
==23100== by 0x43B20E: rule_evaluate (evaluate.c:2915)
==23100== by 0x42FD44: nft_parse (parser_bison.y:727)
==23100== by 0x40768D: nft_run (libnftables.c:86)
==23100== by 0x407DF8: nft_run_cmd_from_filename
(libnftables.c:330)
==23100== by 0x406FC5: main (main.c:292)
> @@ -49,6 +50,10 @@ void parser_init(struct mnl_socket *nf_sock, struct nft_cache *cache,
> state->ectx.nf_sock = nf_sock;
> state->ectx.debug_mask = debug_mask;
> state->ectx.octx = octx;
> + if (variable->identifier != NULL) {
> + struct expr *expr = (struct expr *) variable->expr_value;
This casting is not correct. You need to allocate a symbol expression, eg.
$$ = symbol_expr_alloc(&@$, SYMBOL_DEFINE, scope, $2);
> + symbol_bind(state->scopes[state->scope], variable->identifier, expr);
> + }
prev parent reply other threads:[~2017-12-04 11:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-04 10:52 [PATCH] src: Add option '-D' to define variables from command-line Harsha Sharma
2017-12-04 11:06 ` 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=20171204110635.GA19724@salvia \
--to=pablo@netfilter.org \
--cc=harshasharmaiitr@gmail.com \
--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 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).