From: Florian Westphal <fw@strlen.de>
To: Oliver Ford <ojford@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] iptables: Fix crash on malformed iptables-restore
Date: Thu, 18 May 2017 16:42:18 +0200 [thread overview]
Message-ID: <20170518144218.GC1272@breakpoint.cc> (raw)
In-Reply-To: <1495117105-32762-1-git-send-email-ojford@gmail.com>
Oliver Ford <ojford@gmail.com> wrote:
> --- a/iptables/ip6tables-restore.c
> +++ b/iptables/ip6tables-restore.c
> @@ -165,14 +165,33 @@ static void add_param_to_argv(char *parsestart)
> param_buffer[param_len] = '\0';
>
> /* check if table name specified */
> - if (!strncmp(param_buffer, "-t", 2)
> - || !strncmp(param_buffer, "--table", 8)) {
> + if (param_buffer[0] == '-' && param_buffer[1] != '-'
> + && strchr(param_buffer, 't')) {
> xtables_error(PARAMETER_PROBLEM,
> - "The -t option (seen in line %u) cannot be "
> - "used in ip6tables-restore.\n", line);
> + "The -t option (seen in line %u) cannot be "
> + "used in ip6tables-restore.\n", line);
> + exit(1);
> + } else if (!strncmp(param_buffer, "--", 2)
> + && strchr(param_buffer, 't')) {
Why this strchr() ?
if (!strncmp(param_buffer, "--t", 3) &&
!strncmp(param_buffer, "--table", strlen(param_buffer))
err();
should work.
> + /* If we begin with a '--' and have a 't', check
> + * that the parameter is in the list of valid options */
> + const char* t_options[] = {
If this is needed, I'd suggest
static const char * const t_options[] = {
> + "delete", "insert", "list", "list-rules", "delete-chain",
> + "destination", "dst", "protocol", "in-interface", "match",
> + "out-interface", "wait", "wait-interval", "exact",
> + "fragments", "set-counters", "goto"};
> + int i, opt_len = ARRAY_SIZE(t_options);
> + for (i = 0; i < opt_len; i++) {
> + if (!strcmp(param_buffer + 2, t_options[i])) {
> + goto t_passed;
> + }
> + }
If this t_options[] thing is really needed i'd try to stick this into
a helper function so we don't have to duplicate this in all 3
incarnations.
Thanks for working on this.
next prev parent reply other threads:[~2017-05-18 14:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-18 14:18 [PATCH v2 1/1] iptables: Fix crash on malformed iptables-restore Oliver Ford
2017-05-18 14:42 ` Florian Westphal [this message]
[not found] ` <CAGMVOdswbPCFa1Di6FGGBSznkz36E+iN4b0QJFyS1Ex7JYr75w@mail.gmail.com>
[not found] ` <20170518152003.GD1272@breakpoint.cc>
2017-05-18 15:29 ` Oliver Ford
2017-05-19 9:55 ` Oliver Ford
-- strict thread matches above, loose matches on Subject: below --
2017-05-18 15:21 Oliver Ford
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=20170518144218.GC1272@breakpoint.cc \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=ojford@gmail.com \
/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.