From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH] MASQUERADE: fix --to-ports parser
Date: Tue, 18 May 2010 00:09:55 +0400 [thread overview]
Message-ID: <20100517200955.GB17408@wo.int.altlinux.org> (raw)
In-Reply-To: <4BED339D.60007@trash.net>
Rewrite port range validator to use xtables_strtoui() and
xtables_param_act(). Original check failed to recognize
such port range errors as "1a-2" and "1-2a".
Also, original parser erroneously denied using port 0,
which is now allowed.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
extensions/libipt_MASQUERADE.c | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/extensions/libipt_MASQUERADE.c b/extensions/libipt_MASQUERADE.c
index 9d7fc17..3386ff3 100644
--- a/extensions/libipt_MASQUERADE.c
+++ b/extensions/libipt_MASQUERADE.c
@@ -38,34 +38,34 @@ static void MASQUERADE_init(struct xt_entry_target *t)
static void
parse_ports(const char *arg, struct nf_nat_multi_range *mr)
{
- const char *dash;
- int port;
+ char *end;
+ unsigned int port, maxport;
mr->range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
- port = atoi(arg);
- if (port <= 0 || port > 65535)
- xtables_error(PARAMETER_PROBLEM, "Port \"%s\" not valid\n", arg);
+ if (!xtables_strtoui(arg, &end, &port, 0, UINT16_MAX))
+ xtables_param_act(XTF_BAD_VALUE, "MASQUERADE", "--to-ports", arg);
- dash = strchr(arg, '-');
- if (!dash) {
+ switch (*end) {
+ case '\0':
mr->range[0].min.tcp.port
= mr->range[0].max.tcp.port
= htons(port);
- } else {
- int maxport;
+ return;
+ case '-':
+ if (!xtables_strtoui(end + 1, NULL, &maxport, 0, UINT16_MAX))
+ break;
- maxport = atoi(dash + 1);
- if (maxport == 0 || maxport > 65535)
- xtables_error(PARAMETER_PROBLEM,
- "Port `%s' not valid\n", dash+1);
if (maxport < port)
- /* People are stupid. Present reader excepted. */
- xtables_error(PARAMETER_PROBLEM,
- "Port range `%s' funky\n", arg);
+ break;
+
mr->range[0].min.tcp.port = htons(port);
mr->range[0].max.tcp.port = htons(maxport);
+ return;
+ default:
+ break;
}
+ xtables_param_act(XTF_BAD_VALUE, "MASQUERADE", "--to-ports", arg);
}
static int MASQUERADE_parse(int c, char **argv, int invert, unsigned int *flags,
--
ldv
next prev parent reply other threads:[~2010-05-17 20:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 3:30 [PATCH] MASQUERADE: fix --to-ports parser Dmitry V. Levin
2010-05-14 11:27 ` Patrick McHardy
2010-05-17 20:09 ` Dmitry V. Levin [this message]
2010-05-20 14:01 ` Patrick McHardy
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=20100517200955.GB17408@wo.int.altlinux.org \
--to=ldv@altlinux.org \
--cc=kaber@trash.net \
--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.