* [PATCH] REDIRECT: Fix --to-ports parser
@ 2010-02-19 1:31 Dmitry V. Levin
2010-02-19 3:26 ` Dmitry V. Levin
2010-05-14 11:25 ` Patrick McHardy
0 siblings, 2 replies; 3+ messages in thread
From: Dmitry V. Levin @ 2010-02-19 1:31 UTC (permalink / raw)
To: netfilter-devel
Rewrite port range validator to use xtables_strtoui() and
xtables_param_act(). Original check failed to recognize
several types of port range errors, including:
"-1", "-1a", "-1-a", "a-1", "1a-2", "1-2a", etc.
Also, original parser erroneously denied using port 0,
which is now allowed.
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
extensions/libipt_REDIRECT.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/extensions/libipt_REDIRECT.c b/extensions/libipt_REDIRECT.c
index d39f0bd..3dfcadf 100644
--- a/extensions/libipt_REDIRECT.c
+++ b/extensions/libipt_REDIRECT.c
@@ -39,40 +39,36 @@ static void REDIRECT_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;
- if (strchr(arg, '.'))
- xtables_error(PARAMETER_PROBLEM, "IP address not permitted\n");
+ if (!xtables_strtoui(arg, &end, &port, 0, UINT16_MAX) &&
+ (port = xtables_service_to_port(arg, NULL)) == (unsigned)-1)
+ xtables_param_act(XTF_BAD_VALUE, "REDIRECT", "--to-ports", arg);
- port = atoi(arg);
- if (port == 0)
- port = xtables_service_to_port(arg, NULL);
-
- if (port == 0 || port > 65535)
- xtables_error(PARAMETER_PROBLEM, "Port \"%s\" not valid\n", 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) &&
+ (maxport = xtables_service_to_port(end + 1, NULL)) == (unsigned)-1)
+ 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. */
- 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, "REDIRECT", "--to-ports", arg);
}
static int REDIRECT_parse(int c, char **argv, int invert, unsigned int *flags,
--
ldv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] REDIRECT: Fix --to-ports parser
2010-02-19 1:31 [PATCH] REDIRECT: Fix --to-ports parser Dmitry V. Levin
@ 2010-02-19 3:26 ` Dmitry V. Levin
2010-05-14 11:25 ` Patrick McHardy
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry V. Levin @ 2010-02-19 3:26 UTC (permalink / raw)
To: netfilter-devel
[-- Attachment #1: Type: text/plain, Size: 82 bytes --]
oops, please convert the word "Fix" to lower case before applying.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] REDIRECT: Fix --to-ports parser
2010-02-19 1:31 [PATCH] REDIRECT: Fix --to-ports parser Dmitry V. Levin
2010-02-19 3:26 ` Dmitry V. Levin
@ 2010-05-14 11:25 ` Patrick McHardy
1 sibling, 0 replies; 3+ messages in thread
From: Patrick McHardy @ 2010-05-14 11:25 UTC (permalink / raw)
To: Dmitry V. Levin; +Cc: netfilter-devel
Dmitry V. Levin wrote:
> Rewrite port range validator to use xtables_strtoui() and
> xtables_param_act(). Original check failed to recognize
> several types of port range errors, including:
> "-1", "-1a", "-1-a", "a-1", "1a-2", "1-2a", etc.
> Also, original parser erroneously denied using port 0,
> which is now allowed.
Sorry for the delay, I missed this patch. This looks good me,
applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-14 11:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-19 1:31 [PATCH] REDIRECT: Fix --to-ports parser Dmitry V. Levin
2010-02-19 3:26 ` Dmitry V. Levin
2010-05-14 11:25 ` Patrick McHardy
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).