]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: check for negative numbers in xtables_strtou*
authorJan Engelhardt <jengelh@medozas.de>
Fri, 20 May 2011 14:26:04 +0000 (16:26 +0200)
committerJan Engelhardt <jengelh@medozas.de>
Fri, 20 May 2011 14:56:50 +0000 (16:56 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
xtables.c

index 3c9a13f4b765545837ba9caeda181f9ff2ceaa05..e11a77eeba8bdc5987d0bf641df9fda38b12aae4 100644 (file)
--- 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 <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <netdb.h>
@@ -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)