All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: jeff@garzik.org, davem@davemloft.net
Cc: netdev@vger.kernel.org, gospo@redhat.com,
	Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [ethtool PATCH] ethtool: Can't parse ints with stroul()
Date: Tue, 08 Dec 2009 09:32:40 -0800	[thread overview]
Message-ID: <20091208173240.19917.99052.stgit@localhost.localdomain> (raw)

From: PJ Waskiewicz <peter.p.waskiewicz.jr@intel.com>

A recent change to how int's were being parsed from the command
line had them being read in with an unsigned int string operator.
This didn't allow signed numbers from being read in correctly.
This patch adds a get_uint() routine, and fixes the get_int()
routine to read in signed values.

Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---

 ethtool.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 10dfc80..415ee77 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -324,6 +324,7 @@ typedef enum {
 	CMDL_NONE,
 	CMDL_BOOL,
 	CMDL_INT,
+	CMDL_UINT,
 	CMDL_STR,
 } cmdline_type_t;
 
@@ -404,6 +405,20 @@ static struct cmdline_info cmdline_coalesce[] = {
 
 static int get_int(char *str, int base)
 {
+	long v;
+	char *endp;
+
+	if (!str)
+		show_usage(1);
+	errno = 0;
+	v = strtol(str, &endp, base);
+	if ( errno || *endp || v > INT_MAX)
+		show_usage(1);
+	return (int)v;
+}
+
+static int get_uint(char *str, int base)
+{
 	unsigned long v;
 	char *endp;
 
@@ -413,7 +428,7 @@ static int get_int(char *str, int base)
 	v = strtoul(str, &endp, base);
 	if ( errno || *endp || v > INT_MAX)
 		show_usage(1);
-	return (int)v;
+	return v;
 }
 
 static void parse_generic_cmdline(int argc, char **argp,
@@ -447,6 +462,10 @@ static void parse_generic_cmdline(int argc, char **argp,
 					*p = get_int(argp[i],0);
 					break;
 				}
+				case CMDL_UINT: {
+					*p = get_uint(argp[i],0);
+					break;
+				}
 				case CMDL_STR: {
 					char **s = info[idx].wanted_val;
 					*s = strdup(argp[i]);


             reply	other threads:[~2009-12-08 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08 17:32 Jeff Kirsher [this message]
2009-12-10  1:12 ` [ethtool PATCH] ethtool: Can't parse ints with stroul() Jeff Kirsher
2009-12-23 21:52   ` Jeff Garzik
2009-12-23 21:58     ` Jeff Kirsher
  -- strict thread matches above, loose matches on Subject: below --
2009-12-24  7:22 Jeff Kirsher
2009-12-24  8:29 ` Jeff Garzik

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=20091208173240.19917.99052.stgit@localhost.localdomain \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=davem@davemloft.net \
    --cc=gospo@redhat.com \
    --cc=jeff@garzik.org \
    --cc=netdev@vger.kernel.org \
    --cc=peter.p.waskiewicz.jr@intel.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.