* [ethtool PATCH] ethtool: Can't parse ints with stroul()
@ 2009-12-08 17:32 Jeff Kirsher
2009-12-10 1:12 ` Jeff Kirsher
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Kirsher @ 2009-12-08 17:32 UTC (permalink / raw)
To: jeff, davem; +Cc: netdev, gospo, Peter P Waskiewicz Jr, Jeff Kirsher
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]);
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [ethtool PATCH] ethtool: Can't parse ints with stroul()
2009-12-08 17:32 Jeff Kirsher
@ 2009-12-10 1:12 ` Jeff Kirsher
2009-12-23 21:52 ` Jeff Garzik
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Kirsher @ 2009-12-10 1:12 UTC (permalink / raw)
To: jeff, davem; +Cc: netdev, gospo, Peter P Waskiewicz Jr, Jeff Kirsher
On Tue, Dec 8, 2009 at 09:32, Jeff Kirsher <jeffrey.t.kirsher@intel.com> wrote:
> 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>
> ---
>
Jeff G. - hold off on this patch. We have a version 2 in the works,
because we found if the sign bit was set on a uint, this would fail
parsing.
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ethtool PATCH] ethtool: Can't parse ints with stroul()
2009-12-10 1:12 ` Jeff Kirsher
@ 2009-12-23 21:52 ` Jeff Garzik
2009-12-23 21:58 ` Jeff Kirsher
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Garzik @ 2009-12-23 21:52 UTC (permalink / raw)
To: Jeff Kirsher; +Cc: davem, netdev, gospo, Peter P Waskiewicz Jr
On 12/09/2009 08:12 PM, Jeff Kirsher wrote:
> On Tue, Dec 8, 2009 at 09:32, Jeff Kirsher<jeffrey.t.kirsher@intel.com> wrote:
>> 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>
>> ---
>>
>
> Jeff G. - hold off on this patch. We have a version 2 in the works,
> because we found if the sign bit was set on a uint, this would fail
> parsing.
Was version 2 ever posted? I never saw it...
Jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ethtool PATCH] ethtool: Can't parse ints with stroul()
2009-12-23 21:52 ` Jeff Garzik
@ 2009-12-23 21:58 ` Jeff Kirsher
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Kirsher @ 2009-12-23 21:58 UTC (permalink / raw)
To: Jeff Garzik; +Cc: davem, netdev, gospo, Peter P Waskiewicz Jr
On Wed, Dec 23, 2009 at 13:52, Jeff Garzik <jeff@garzik.org> wrote:
> On 12/09/2009 08:12 PM, Jeff Kirsher wrote:
>>
>> On Tue, Dec 8, 2009 at 09:32, Jeff Kirsher<jeffrey.t.kirsher@intel.com>
>> wrote:
>>>
>>> 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>
>>> ---
>>>
>>
>> Jeff G. - hold off on this patch. We have a version 2 in the works,
>> because we found if the sign bit was set on a uint, this would fail
>> parsing.
>
> Was version 2 ever posted? I never saw it...
>
> Jeff
>
Not yet, version 2 of the patch is in test right now. I should have
it sent out either later tonight or tomorrow.
--
Cheers,
Jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ethtool PATCH] ethtool: Can't parse ints with stroul()
@ 2009-12-24 7:22 Jeff Kirsher
2009-12-24 8:29 ` Jeff Garzik
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Kirsher @ 2009-12-24 7:22 UTC (permalink / raw)
To: davem, jeff; +Cc: netdev, gospo, Peter P Waskiewicz Jr, Jeff Kirsher
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 | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index 4b750a4..10ff1f1 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,18 +405,32 @@ static struct cmdline_info cmdline_coalesce[] = {
static int get_int(char *str, int base)
{
- unsigned long v;
+ long v;
char *endp;
if (!str)
show_usage(1);
errno = 0;
- v = strtoul(str, &endp, base);
+ 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;
+
+ if (!str)
+ show_usage(1);
+ errno = 0;
+ v = strtoul(str, &endp, base);
+ if ( errno || *endp || v > UINT_MAX)
+ show_usage(1);
+ return v;
+}
+
static void parse_generic_cmdline(int argc, char **argp,
int first_arg, int *changed,
struct cmdline_info *info,
@@ -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]);
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [ethtool PATCH] ethtool: Can't parse ints with stroul()
2009-12-24 7:22 [ethtool PATCH] ethtool: Can't parse ints with stroul() Jeff Kirsher
@ 2009-12-24 8:29 ` Jeff Garzik
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Garzik @ 2009-12-24 8:29 UTC (permalink / raw)
To: Jeff Kirsher; +Cc: davem, netdev, gospo, Peter P Waskiewicz Jr
On 12/24/2009 02:22 AM, Jeff Kirsher wrote:
> 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 | 23 +++++++++++++++++++++--
> 1 files changed, 21 insertions(+), 2 deletions(-)
applied
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-12-24 8:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-24 7:22 [ethtool PATCH] ethtool: Can't parse ints with stroul() Jeff Kirsher
2009-12-24 8:29 ` Jeff Garzik
-- strict thread matches above, loose matches on Subject: below --
2009-12-08 17:32 Jeff Kirsher
2009-12-10 1:12 ` Jeff Kirsher
2009-12-23 21:52 ` Jeff Garzik
2009-12-23 21:58 ` Jeff Kirsher
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).