[PATCH] string_to_number issue
Brad Chapman
kakadu@earthlink.net
Sun, 22 Jul 2001 07:35:00 -0400
This is a multi-part message in MIME format.
--------------090109000009070302060604
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Everyone,
Here is a patch which _finally_ fixes the string_to_number
issue. According to strtoul(3) for my glibc library, it will
perform negation of the converted value before returning it. I
just hope this is the case for glibc (and other C libraries)
everywhere.
Brad
<snip>
--- userspace/iptables.c Thu Jun 28 16:37:26 2001
+++ userspace/iptables.c Sun Jul 22 07:29:56 2001
@@ -851,9 +851,10 @@
long number;
char *end;
- /* Handle hex, octal, etc. */
+ /* Handle hex, octal, etc. with strtoul(), which
+ handles unsigned and signed */
errno = 0;
- number = strtol(s, &end, 0);
+ number = strtoul(s, &end, 0);
if (*end == '\0' && end != s) {
/* we parsed a number, let's see if we want this */
if (errno != ERANGE && min <= number && number <= max)
--- userspace/ip6tables.c Thu Jun 28 16:37:19 2001
+++ userspace/ip6tables.c Sun Jul 22 07:30:56 2001
@@ -826,12 +826,13 @@
int
string_to_number(const char *s, int min, int max)
{
- long number;
+ long number;
char *end;
- /* Handle hex, octal, etc. */
- errno = 0;
- number = strtol(s, &end, 0);
+ /* Handle hex, octal, etc. with strtoul(), which
+ handles unsigned and signed */
+ errno = 0;
+ number = strtoul(s, &end, 0);
if (*end == '\0' && end != s) {
/* we parsed a number, let's see if we want this */
if (errno != ERANGE && min <= number && number <= max)
<snip>
--------------090109000009070302060604
Content-Type: text/plain;
name="stringtonumber.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="stringtonumber.patch"
--- userspace/iptables.c Thu Jun 28 16:37:26 2001
+++ userspace/iptables.c Sun Jul 22 07:29:56 2001
@@ -851,9 +851,10 @@
long number;
char *end;
- /* Handle hex, octal, etc. */
+ /* Handle hex, octal, etc. with strtoul(), which
+ handles unsigned and signed */
errno = 0;
- number = strtol(s, &end, 0);
+ number = strtoul(s, &end, 0);
if (*end == '\0' && end != s) {
/* we parsed a number, let's see if we want this */
if (errno != ERANGE && min <= number && number <= max)
--- userspace/ip6tables.c Thu Jun 28 16:37:19 2001
+++ userspace/ip6tables.c Sun Jul 22 07:30:56 2001
@@ -826,12 +826,13 @@
int
string_to_number(const char *s, int min, int max)
{
- long number;
+ long number;
char *end;
- /* Handle hex, octal, etc. */
- errno = 0;
- number = strtol(s, &end, 0);
+ /* Handle hex, octal, etc. with strtoul(), which
+ handles unsigned and signed */
+ errno = 0;
+ number = strtoul(s, &end, 0);
if (*end == '\0' && end != s) {
/* we parsed a number, let's see if we want this */
if (errno != ERANGE && min <= number && number <= max)
--------------090109000009070302060604--