From 2305d5fb42fc059f38fc1bdf53411dbeecdb310b Mon Sep 17 00:00:00 2001 From: JP Abgrall Date: Wed, 18 May 2011 20:26:14 -0700 Subject: libxt_quota: make sure uint64 is not truncated The xtables_strtoul() would cram a long long into a long. The parse_int would try to cram a UINT64 into a long. --- xtables.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xtables.c') diff --git a/xtables.c b/xtables.c index f10cdb70..3c9a13f4 100644 --- a/xtables.c +++ b/xtables.c @@ -426,7 +426,7 @@ int xtables_load_ko(const char *modprobe, bool quiet) * Returns true/false whether number was accepted. On failure, *value has * undefined contents. */ -bool xtables_strtoul(const char *s, char **end, unsigned long *value, +bool xtables_strtoul(const char *s, char **end, unsigned long long *value, unsigned long min, unsigned long max) { unsigned long v; @@ -454,7 +454,7 @@ bool xtables_strtoul(const char *s, char **end, unsigned long *value, bool xtables_strtoui(const char *s, char **end, unsigned int *value, unsigned int min, unsigned int max) { - unsigned long v; + unsigned long long v; bool ret; ret = xtables_strtoul(s, end, &v, min, max); -- cgit v1.2.3 From d61b02fbbbe7f6e643aad8649c8559c175c68c52 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 20 May 2011 16:26:04 +0200 Subject: libxtables: check for negative numbers in xtables_strtou* Signed-off-by: Jan Engelhardt --- xtables.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'xtables.c') diff --git a/xtables.c b/xtables.c index 3c9a13f4..e11a77ee 100644 --- a/xtables.c +++ b/xtables.c @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - +#include #include #include #include @@ -430,11 +430,16 @@ bool xtables_strtoul(const char *s, char **end, unsigned long long *value, unsigned long min, unsigned long max) { unsigned long v; + const char *p; char *my_end; errno = 0; + /* Since strtoul allows leading minus, we have to check for ourself. */ + for (p = s; isspace(*p); ++p) + ; + if (*p == '-') + return false; v = strtoul(s, &my_end, 0); - if (my_end == s) return false; if (end != NULL) -- cgit v1.2.3 From 0b7a140944738d67b9c4e6f09992c8407eefb18a Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 24 May 2011 02:30:23 +0200 Subject: libxtables: use uintmax for xtables_strtoul Addendum to 2305d5fb42fc059f38fc1bdf53411dbeecdb310b. I noticed that unsigned long long is not consistently used, for example, min/max are still just unsigned long, and strtoul is being called. Instead of changing it to unsigned long long, just use uintmax functions right away so this does not need size-related changing in the future. Cc: JP Abgrall Signed-off-by: Jan Engelhardt --- xtables.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'xtables.c') diff --git a/xtables.c b/xtables.c index e11a77ee..acfcf8bd 100644 --- a/xtables.c +++ b/xtables.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -426,10 +427,10 @@ int xtables_load_ko(const char *modprobe, bool quiet) * Returns true/false whether number was accepted. On failure, *value has * undefined contents. */ -bool xtables_strtoul(const char *s, char **end, unsigned long long *value, - unsigned long min, unsigned long max) +bool xtables_strtoul(const char *s, char **end, uintmax_t *value, + uintmax_t min, uintmax_t max) { - unsigned long v; + uintmax_t v; const char *p; char *my_end; @@ -439,7 +440,7 @@ bool xtables_strtoul(const char *s, char **end, unsigned long long *value, ; if (*p == '-') return false; - v = strtoul(s, &my_end, 0); + v = strtoumax(s, &my_end, 0); if (my_end == s) return false; if (end != NULL) @@ -459,7 +460,7 @@ bool xtables_strtoul(const char *s, char **end, unsigned long long *value, bool xtables_strtoui(const char *s, char **end, unsigned int *value, unsigned int min, unsigned int max) { - unsigned long long v; + uintmax_t v; bool ret; ret = xtables_strtoul(s, end, &v, min, max); -- cgit v1.2.3