netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 10/10] libxtables: make multiint parser have greater range
Date: Tue, 24 May 2011 03:21:41 +0200	[thread overview]
Message-ID: <1306200102-12148-11-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1306200102-12148-1-git-send-email-jengelh@medozas.de>

Since parse_mint can handle XTTYPE_UINT64RC, it must allow numbers
larger than UINT32_MAX.

Cc: JP Abgrall <jpa@google.com>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 xtoptions.c |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/xtoptions.c b/xtoptions.c
index e9736a4..1fc90ee 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -98,21 +98,35 @@ xtables_options_xfrm(struct option *orig_opts, struct option *oldopts,
 	return merge;
 }
 
+static uintmax_t xtopt_max_by_type(enum xt_option_type type)
+{
+	switch (type) {
+	case XTTYPE_UINT8:
+	case XTTYPE_UINT8RC:
+		return UINT8_MAX;
+	case XTTYPE_UINT16:
+	case XTTYPE_UINT16RC:
+		return UINT16_MAX;
+	case XTTYPE_UINT32:
+	case XTTYPE_UINT32RC:
+		return UINT32_MAX;
+	case XTTYPE_UINT64:
+	case XTTYPE_UINT64RC:
+		return UINT64_MAX;
+	default:
+		return 0;
+	}
+}
+
 /**
  * Require a simple integer.
  */
 static void xtopt_parse_int(struct xt_option_call *cb)
 {
 	const struct xt_option_entry *entry = cb->entry;
-	uintmax_t lmin = 0, lmax = UINT32_MAX;
+	uintmax_t lmin = 0, lmax = xtopt_max_by_type(entry->type);
 	uintmax_t value;
 
-	if (entry->type == XTTYPE_UINT8)
-		lmax = UINT8_MAX;
-	else if (entry->type == XTTYPE_UINT16)
-		lmax = UINT16_MAX;
-	else if (entry->type == XTTYPE_UINT64)
-		lmax = UINT64_MAX;
 	if (cb->entry->min != 0)
 		lmin = cb->entry->min;
 	if (cb->entry->max != 0)
@@ -180,8 +194,10 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
 	const struct xt_option_entry *entry = cb->entry;
 	const char *arg = cb->arg;
 	size_t esize = sizeof(uint32_t);
+	uintmax_t lmax = xtopt_max_by_type(entry->type);
 	char *put = XTOPT_MKPTR(cb);
-	unsigned int maxiter, value;
+	unsigned int maxiter;
+	uintmax_t value;
 	char *end = "";
 	char sep = ':';
 
@@ -204,11 +220,11 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
 			xt_params->exit_err(PARAMETER_PROBLEM, "%s: Too many "
 				"components for option \"--%s\" (max: %u)\n",
 				cb->ext_name, entry->name, maxiter);
-		if (!xtables_strtoui(arg, &end, &value, 0, UINT32_MAX))
+		if (!xtables_strtoul(arg, &end, &value, 0, lmax))
 			xt_params->exit_err(PARAMETER_PROBLEM,
 				"%s: bad value for option \"--%s\" near "
-				"\"%s\", or out of range (0-%u).\n",
-				cb->ext_name, entry->name, arg, UINT32_MAX);
+				"\"%s\", or out of range (0-%ju).\n",
+				cb->ext_name, entry->name, arg, lmax);
 		if (*end != '\0' && *end != sep)
 			xt_params->exit_err(PARAMETER_PROBLEM,
 				"%s: Argument to \"--%s\" has unexpected "
-- 
1.7.3.4


      parent reply	other threads:[~2011-05-24  1:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-24  1:21 Option parsing fixes (t-10) Jan Engelhardt
2011-05-24  1:21 ` [PATCH 01/10] libxt_time: always ignore libc timezone Jan Engelhardt
2011-05-24  1:21 ` [PATCH 02/10] libxt_time: --utc and --localtz are mutually exclusive Jan Engelhardt
2011-05-24  1:21 ` [PATCH 03/10] doc: use .IP list for TCPMSS Jan Engelhardt
2011-05-24  1:21 ` [PATCH 04/10] doc: remove redundant .IP calls in libxt_time Jan Engelhardt
2011-05-24  1:21 ` [PATCH 05/10] libxt_time: remove --localtz option Jan Engelhardt
2011-05-24  1:21 ` [PATCH 06/10] libxt_u32: --u32 option is required Jan Engelhardt
2011-05-24  1:21 ` [PATCH 07/10] libip6t_rt: restore --rt-type storing Jan Engelhardt
2011-05-24  1:21 ` [PATCH 08/10] libxtables: more detailed error message on multi-int parsing Jan Engelhardt
2011-05-24  1:21 ` [PATCH 09/10] libxtables: use uintmax for xtables_strtoul Jan Engelhardt
2011-05-24  1:21 ` Jan Engelhardt [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=1306200102-12148-11-git-send-email-jengelh@medozas.de \
    --to=jengelh@medozas.de \
    --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 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).